sea-chart 0.0.90 → 0.0.92

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
  }
@@ -237,7 +237,7 @@ BaseUtils.isSameGroup = (isColumnDataAsAnArray, source, target) => {
237
237
  if (Array.isArray(source) && Array.isArray(target)) {
238
238
  return JSON.stringify(source) === JSON.stringify(target);
239
239
  }
240
- return (!Array.isArray(source) || source.length === 0) && !target || source.includes(target);
240
+ return (!Array.isArray(source) || source.length === 0) && !target || (source === null || source === void 0 ? void 0 : source.includes(target));
241
241
  }
242
242
  return source === null && target === null || source === undefined && target === undefined || source === target;
243
243
  };
@@ -1,6 +1,6 @@
1
1
  import dayjs from 'dayjs';
2
2
  import { CellType, DATE_COLUMN_OPTIONS, FORMULA_COLUMN_TYPES_MAP, getTableById, getViewById, getTableColumnByKey } from 'dtable-utils';
3
- import { CHART_SUMMARY_TYPE, CHART_TYPE, Y_AXIS_TYPE_PREFIX } from '../../../constants';
3
+ import { CHART_STYLE_COLORS, CHART_SUMMARY_TYPE, CHART_TYPE, Y_AXIS_TYPE_PREFIX } from '../../../constants';
4
4
  import { getColorFromSingleSelectColumn, islinkDateFormula } from '../../column-utils';
5
5
  import { isArrayCellValue } from '../../cell-value-utils';
6
6
  import { getFormattedLabel, isValidRow } from '../../row-utils';
@@ -175,6 +175,7 @@ async function calculateGroupingChart(chart, value, _ref2) {
175
175
  results = results.map(result => {
176
176
  return {
177
177
  ...result,
178
+ group_color: result.color || CHART_STYLE_COLORS[0],
178
179
  name: getFormattedLabel(groupbyColumn, result.name, value.collaborators)
179
180
  };
180
181
  });
@@ -439,6 +440,7 @@ async function calculateCustomBar(statItem, value, _ref4) {
439
440
  getTableFormulaResults
440
441
  } = _ref4;
441
442
  const {
443
+ type,
442
444
  table_id,
443
445
  view_id,
444
446
  x_axis_column_key,
@@ -497,7 +499,7 @@ async function calculateCustomBar(statItem, value, _ref4) {
497
499
  results = results.map(result => {
498
500
  return {
499
501
  ...result,
500
- name: getFormattedLabel(groupbyColumn, result.name, value.collaborators)
502
+ name: getFormattedLabel(groupbyColumn, result.name, value.collaborators, type)
501
503
  };
502
504
  });
503
505
  return results;
@@ -1,7 +1,7 @@
1
1
  import { isNumber, getTableById, getViewById, getTableColumnByKey } from 'dtable-utils';
2
2
  import BaseUtils from '../base-utils';
3
3
  import { isArrayCellValue } from '../../cell-value-utils';
4
- import { LABEL_COLORS, CHART_SUMMARY_TYPE } from '../../../constants';
4
+ import { CHART_SUMMARY_TYPE, STYLE_COLORS } from '../../../constants';
5
5
  import { getCellValue, getFormattedLabel } from '../../row-utils';
6
6
  async function calculator(chart, value, _ref) {
7
7
  let {
@@ -22,7 +22,8 @@ async function calculator(chart, value, _ref) {
22
22
  y_axis_left_summary_method,
23
23
  y_axis_right_summary_method,
24
24
  y_axis_left_group_by_multiple_numeric_column,
25
- y_axis_left_group_by_numeric_columns
25
+ y_axis_left_group_by_numeric_columns,
26
+ type
26
27
  } = chart;
27
28
  const table = getTableById(value.tables, table_id);
28
29
  const view = table && getViewById(table.views, view_id);
@@ -47,7 +48,7 @@ async function calculator(chart, value, _ref) {
47
48
  column_name: column1.name,
48
49
  type: column1.type,
49
50
  data: column1.data,
50
- color: LABEL_COLORS[0]
51
+ color: STYLE_COLORS[0].colors[0]
51
52
  };
52
53
  }
53
54
  if (y_axis_left_group_by_multiple_numeric_column) {
@@ -59,7 +60,7 @@ async function calculator(chart, value, _ref) {
59
60
  column_name: summaryColumn.name,
60
61
  type: summaryColumn.type,
61
62
  data: summaryColumn.data,
62
- color: LABEL_COLORS[(index + 1) % 12]
63
+ color: STYLE_COLORS[0].colors[index % 12]
63
64
  };
64
65
  }
65
66
  });
@@ -244,7 +245,7 @@ async function calculator(chart, value, _ref) {
244
245
  formatted_value_right: formattedValueRight
245
246
  });
246
247
  } else {
247
- leftSummaryColumnKeys.forEach(columnKey => {
248
+ leftSummaryColumnKeys.forEach((columnKey, index) => {
248
249
  const summaryColumn = leftSummaryColumn[columnKey];
249
250
  const summaryMethod = summaryColumn.method;
250
251
  const list = leftValue[columnKey];
@@ -254,7 +255,8 @@ async function calculator(chart, value, _ref) {
254
255
  name: key,
255
256
  value_left: value,
256
257
  group_name: summaryColumn.column_name,
257
- color: leftSummaryColumn[columnKey].color,
258
+ // color: leftSummaryColumn[columnKey].color,
259
+ color: STYLE_COLORS[0].colors[index % 12],
258
260
  value_right: value2,
259
261
  formatted_value_left: formattedValueLeft,
260
262
  formatted_value_right: formattedValueRight
@@ -264,7 +266,7 @@ async function calculator(chart, value, _ref) {
264
266
  }
265
267
  BaseUtils.sortCharts(results, xAxisColumn, 'name');
266
268
  results.forEach(item => {
267
- item.name = getFormattedLabel(xAxisColumn, item.name, value.collaborators);
269
+ item.name = getFormattedLabel(xAxisColumn, item.name, value.collaborators, type);
268
270
  });
269
271
  return results;
270
272
  }
@@ -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
  }
@@ -87,7 +87,7 @@ async function calculateOneDimensionTable(chart, value, _ref) {
87
87
  }).filter(item => getTableColumnByKey(table, item.key));
88
88
  pivot_rows.forEach(row => {
89
89
  row.original_name = row.name;
90
- row.name = getFormattedLabel(column, row.name, value.collaborators);
90
+ row.name = getFormattedLabel(column, row.name, value.collaborators, chart.type);
91
91
  });
92
92
  return {
93
93
  pivot_columns_total,
@@ -284,22 +284,52 @@ 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
 
294
324
  // format shown label(name)
295
325
  const map = {};
296
326
  pivot_columns.forEach(column => {
297
- const name = getFormattedLabel(rowGroupbyColumn, column.key, value.collaborators);
327
+ const name = getFormattedLabel(rowGroupbyColumn, column.key, value.collaborators, chart.type);
298
328
  map[column.key] = name;
299
329
  column.key = name;
300
330
  });
301
331
  pivot_rows.forEach(row => {
302
- row.name = getFormattedLabel(groupbyColumn, row.name, value.collaborators);
332
+ row.name = getFormattedLabel(groupbyColumn, row.name, value.collaborators, chart.type);
303
333
  const cells = {};
304
334
  Object.keys(row.cells).forEach(key => {
305
335
  cells[map[key]] = row.cells[key];
@@ -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
  }
@@ -5,7 +5,6 @@ import { isObject } from 'lodash';
5
5
  import { CHART_SUMMARY_TYPE, CHART_TYPE, SUPPORT_DATA_SORT_CHART_TYPES, TABLE_DIMENSIONS, Y_AXIS_TYPE_PREFIX, STYLE_COLORS, TREND_TYPES } from '../../constants';
6
6
  import { chartColumn2SqlColumn, summaryMethodColumn2SqlColumn } from '../sql';
7
7
  import { getClientLinkDisplayString } from '../cell-format-utils';
8
- import context from '../../context';
9
8
  import { column2SqlColumn } from '../sql/column-2-sql-column';
10
9
  import { formatNumericValue, getFormattedValue, getSummaryResult } from '../column-utils';
11
10
  import { getCompareDate } from '../trend-utils';
@@ -16,7 +15,6 @@ _SQLStatisticsUtils = SQLStatisticsUtils;
16
15
  SQLStatisticsUtils.dataSources = 'sql_statistics';
17
16
  SQLStatisticsUtils.getGroupLabelFromDB = (cellValue, column, chart) => {
18
17
  const dateGranularity = BaseUtils.getDateGranularityByType(chart);
19
- const collaborators = context.getCollaboratorsFromCache();
20
18
  const {
21
19
  type,
22
20
  data
@@ -58,7 +56,6 @@ SQLStatisticsUtils.getGroupLabelFromDB = (cellValue, column, chart) => {
58
56
  }
59
57
  case CellType.COLLABORATOR:
60
58
  {
61
- if (!Array.isArray(collaborators) || collaborators.length === 0) return [];
62
59
  if (!Array.isArray(cellValue) || cellValue.length === 0) return [];
63
60
  return cellValue;
64
61
  }
@@ -842,6 +839,43 @@ SQLStatisticsUtils.customChartSQLResult2JavaScript = (chart, sqlRows, chartSQLMa
842
839
  });
843
840
  result = result.concat(groupItems);
844
841
  });
842
+ const isCellValueAsAnArray = MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP[groupbyColumn.type];
843
+ if (isCellValueAsAnArray) {
844
+ const takenApart = [];
845
+ const assembled = [];
846
+ // take apart cell value of arrays, and then assemble them by name and group_name
847
+ result.forEach(item => {
848
+ const {
849
+ name: names
850
+ } = item;
851
+ if (!Array.isArray(names)) return;
852
+ names.forEach(name => {
853
+ takenApart.push({
854
+ ...item,
855
+ name,
856
+ original_name: name
857
+ });
858
+ });
859
+ });
860
+ takenApart.forEach(item => {
861
+ const {
862
+ name,
863
+ group_name
864
+ } = item;
865
+ const index = assembled.findIndex(r => r.name === name && r.group_name === group_name);
866
+ if (index < 0) {
867
+ assembled.push({
868
+ ...item
869
+ });
870
+ } else {
871
+ // TODO: formatted_value maybe need to be handled, but it's useless by now
872
+ assembled[index].value += item.value;
873
+ }
874
+ });
875
+ result = assembled;
876
+ }
877
+ BaseUtils.updateTableViewList(result, groupbyColumn, 'name', '');
878
+ BaseUtils.sortCharts(result, groupbyColumn, 'name');
845
879
  return result;
846
880
  };
847
881
  SQLStatisticsUtils.compareSQLResult2Javascript = (chart, sqlRows, chartSQLMap, columnMap, tables) => {
@@ -993,7 +1027,7 @@ SQLStatisticsUtils.combinationSQLResult2Javascript = (chart, sqlRows, chartSQLMa
993
1027
  if (y_axis_right_summary_type === CHART_SUMMARY_TYPE.ADVANCED) {
994
1028
  rightSummaryColumn = getTableColumnByKey(table, y_axis_right_summary_column);
995
1029
  }
996
- sqlRows.forEach(row => {
1030
+ sqlRows.forEach((row, index) => {
997
1031
  const cellValue = row[sqlGroupbyColumnKey];
998
1032
  const summaryValue = row[sqlSummaryColumnKey];
999
1033
  const key = _SQLStatisticsUtils.getGroupLabelFromDB(cellValue, groupbyColumn, chart.config);
@@ -1010,7 +1044,8 @@ SQLStatisticsUtils.combinationSQLResult2Javascript = (chart, sqlRows, chartSQLMa
1010
1044
  let itemIdx = result.findIndex(v => v.name === null);
1011
1045
  if (itemIdx < 0) {
1012
1046
  result.push({
1013
- color: '',
1047
+ // color is defined by index of the name
1048
+ color: STYLE_COLORS[0].colors[index % 12],
1014
1049
  name: null,
1015
1050
  rows: [row],
1016
1051
  value_left: valueLeft,
@@ -1019,15 +1054,15 @@ SQLStatisticsUtils.combinationSQLResult2Javascript = (chart, sqlRows, chartSQLMa
1019
1054
  } else {
1020
1055
  let itemRow = result[itemIdx];
1021
1056
  itemRow.rows.push(row);
1022
- itemRow.value_left = itemRow.value_left + summaryValue;
1023
- itemRow.value_right = itemRow.value_right + summaryValue;
1057
+ itemRow.value_left = itemRow.value_left + valueLeft;
1058
+ itemRow.value_right = itemRow.value_right + valueRight;
1024
1059
  }
1025
1060
  } else {
1026
1061
  key.forEach(item => {
1027
1062
  let itemIdx = result.findIndex(v => v.name === item);
1028
1063
  if (itemIdx < 0) {
1029
1064
  result.push({
1030
- color: '',
1065
+ color: STYLE_COLORS[0].colors[index % 12],
1031
1066
  name: item,
1032
1067
  rows: [row],
1033
1068
  value_left: valueLeft,
@@ -1036,8 +1071,8 @@ SQLStatisticsUtils.combinationSQLResult2Javascript = (chart, sqlRows, chartSQLMa
1036
1071
  } else {
1037
1072
  let itemRow = result[itemIdx];
1038
1073
  itemRow.rows.push(row);
1039
- itemRow.value_left = itemRow.value_left + summaryValue;
1040
- itemRow.value_right = itemRow.value_right + summaryValue;
1074
+ itemRow.value_left = itemRow.value_left + valueLeft;
1075
+ itemRow.value_right = itemRow.value_right + valueRight;
1041
1076
  }
1042
1077
  });
1043
1078
  }
@@ -1045,7 +1080,7 @@ SQLStatisticsUtils.combinationSQLResult2Javascript = (chart, sqlRows, chartSQLMa
1045
1080
  let itemIdx = result.findIndex(v => v.name === key);
1046
1081
  if (itemIdx < 0) {
1047
1082
  result.push({
1048
- color: '',
1083
+ color: STYLE_COLORS[0].colors[index % 12],
1049
1084
  name: key,
1050
1085
  rows: [row],
1051
1086
  value_left: valueLeft,
@@ -1054,8 +1089,8 @@ SQLStatisticsUtils.combinationSQLResult2Javascript = (chart, sqlRows, chartSQLMa
1054
1089
  } else {
1055
1090
  let itemRow = result[itemIdx];
1056
1091
  itemRow.rows.push(row);
1057
- itemRow.value_left = itemRow.value_left + summaryValue;
1058
- itemRow.value_right = itemRow.value_right + summaryValue;
1092
+ itemRow.value_left = itemRow.value_left + valueLeft;
1093
+ itemRow.value_right = itemRow.value_right + valueRight;
1059
1094
  }
1060
1095
  }
1061
1096
  });
@@ -1078,7 +1113,6 @@ SQLStatisticsUtils.combinationSQLResult2Javascript = (chart, sqlRows, chartSQLMa
1078
1113
  if (!exists && leftSummaryColumn) {
1079
1114
  groupItems.push(groupItem);
1080
1115
  }
1081
- // leftSummaryColumn && !groupItems.includes(groupItem) && groupItems.push(groupItem);
1082
1116
  y_axis_left_group_by_numeric_columns.forEach((item, index) => {
1083
1117
  const column = getTableColumnByKey(table, item.column_key);
1084
1118
  if (column) {
@@ -1094,7 +1128,6 @@ SQLStatisticsUtils.combinationSQLResult2Javascript = (chart, sqlRows, chartSQLMa
1094
1128
  if (!exists) {
1095
1129
  groupItems.push(groupItem);
1096
1130
  }
1097
- // !groupItems.includes(groupItem) && groupItems.push(groupItem);
1098
1131
  }
1099
1132
  });
1100
1133
  sqlRows.forEach((item, index) => {
@@ -1104,24 +1137,58 @@ SQLStatisticsUtils.combinationSQLResult2Javascript = (chart, sqlRows, chartSQLMa
1104
1137
  if (y_axis_right_summary_type === CHART_SUMMARY_TYPE.ADVANCED) {
1105
1138
  valueRight = BaseUtils.getPrecisionNumber(valueRight, rightSummaryColumn.data);
1106
1139
  }
1107
- groupItems.forEach((groupItem, index) => {
1108
- var _groupItem$column;
1109
- const sqlName = groupItem.sqlName;
1110
- const groupName = (_groupItem$column = groupItem.column) === null || _groupItem$column === void 0 ? void 0 : _groupItem$column.name;
1111
- let value = item[sqlName] || 0;
1112
- if (y_axis_right_summary_type === CHART_SUMMARY_TYPE.ADVANCED) {
1113
- value = BaseUtils.getPrecisionNumber(value, leftSummaryColumn.data);
1114
- }
1115
- result.push({
1116
- name: key,
1117
- value_left: value,
1118
- value_right: valueRight,
1119
- group_name: groupName,
1120
- color: STYLE_COLORS[0].colors[index % 12]
1140
+ if (isGroupbyColumnDataAsAnArray) {
1141
+ key.forEach(key => {
1142
+ groupItems.forEach((groupItem, index) => {
1143
+ var _groupItem$column;
1144
+ const sqlName = groupItem.sqlName;
1145
+ const groupName = (_groupItem$column = groupItem.column) === null || _groupItem$column === void 0 ? void 0 : _groupItem$column.name;
1146
+ let value = item[sqlName] || 0;
1147
+ if (y_axis_right_summary_type === CHART_SUMMARY_TYPE.ADVANCED) {
1148
+ value = BaseUtils.getPrecisionNumber(value, leftSummaryColumn.data);
1149
+ }
1150
+ const itemIdx = result.findIndex(v => {
1151
+ var _groupItem$column2;
1152
+ return v.group_name === ((_groupItem$column2 = groupItem.column) === null || _groupItem$column2 === void 0 ? void 0 : _groupItem$column2.name) && v.name === key;
1153
+ });
1154
+ if (itemIdx < 0) {
1155
+ result.push({
1156
+ name: key,
1157
+ value_left: value,
1158
+ value_right: valueRight,
1159
+ group_name: groupName,
1160
+ // for multiple numeric_columns, color is defined by group_name
1161
+ color: STYLE_COLORS[0].colors[index % 12]
1162
+ });
1163
+ } else {
1164
+ const itemRow = result[itemIdx];
1165
+ itemRow.value_left = itemRow.value_left + value;
1166
+ itemRow.value_right = itemRow.value_right + valueRight;
1167
+ }
1168
+ });
1121
1169
  });
1122
- });
1170
+ } else {
1171
+ groupItems.forEach((groupItem, index) => {
1172
+ var _groupItem$column3;
1173
+ const sqlName = groupItem.sqlName;
1174
+ const groupName = (_groupItem$column3 = groupItem.column) === null || _groupItem$column3 === void 0 ? void 0 : _groupItem$column3.name;
1175
+ let value = item[sqlName] || 0;
1176
+ if (y_axis_right_summary_type === CHART_SUMMARY_TYPE.ADVANCED) {
1177
+ value = BaseUtils.getPrecisionNumber(value, leftSummaryColumn.data);
1178
+ }
1179
+ result.push({
1180
+ name: key,
1181
+ value_left: value,
1182
+ value_right: valueRight,
1183
+ group_name: groupName,
1184
+ color: STYLE_COLORS[0].colors[index % 12]
1185
+ });
1186
+ });
1187
+ }
1123
1188
  });
1124
1189
  }
1190
+ BaseUtils.updateTableViewList(result, groupbyColumn, 'name', '');
1191
+ BaseUtils.sortCharts(result, groupbyColumn, 'name');
1125
1192
  return result;
1126
1193
  };
1127
1194
  SQLStatisticsUtils.dashboardSQLResult2JavaScript = (chart, sqlRows, chartSQLMap, columnMap, tables) => {
@@ -1,4 +1,5 @@
1
- import { CellType, COLLABORATOR_COLUMN_TYPES, FORMULA_COLUMN_TYPES_MAP, FORMULA_RESULT_TYPE, isNumber, getNumberDisplayString } from 'dtable-utils';
1
+ import { CellType, COLLABORATOR_COLUMN_TYPES, FORMULA_COLUMN_TYPES_MAP, FORMULA_RESULT_TYPE, isNumber, getNumberDisplayString, getOption, getColumnOptions } from 'dtable-utils';
2
+ import { CHART_TYPE } from '../constants';
2
3
  import { getClientFormulaDisplayString } from './cell-format-utils';
3
4
  export const isEmptyGeolocationCell = (cellValue, format) => {
4
5
  if (!cellValue) return null;
@@ -28,7 +29,8 @@ export const isValidRow = (row, formulaRow, column, includeEmpty) => {
28
29
  }
29
30
  return cellValue || cellValue === 0;
30
31
  };
31
- export const getFormattedLabel = (column, name, collaborators) => {
32
+ const RETURN_ARRAY_CHART_TYPES = [CHART_TYPE.TABLE];
33
+ export const getFormattedLabel = (column, name, collaborators, chartType) => {
32
34
  let {
33
35
  type: columnType,
34
36
  data: columnData
@@ -50,10 +52,21 @@ export const getFormattedLabel = (column, name, collaborators) => {
50
52
  }
51
53
  } else if (columnType === CellType.MULTIPLE_SELECT) {
52
54
  // Return the array directly and process it in the rendering, file directly: src/view/wrapper/table/pivot-table-display-name.js
53
- if (Array.isArray(name)) {
54
- return name;
55
+ if (RETURN_ARRAY_CHART_TYPES.includes(chartType)) {
56
+ if (Array.isArray(name)) {
57
+ return name;
58
+ }
59
+ return [];
55
60
  }
56
- return [];
61
+ const options = getColumnOptions(column);
62
+ let selectedOption = getOption(options, name);
63
+ let {
64
+ name: optionName,
65
+ color: optionColor
66
+ } = selectedOption || {};
67
+ // TODO:use option‘s color
68
+ // return { name: optionName, color: optionColor };
69
+ return optionName;
57
70
  } else if (columnType === CellType.COLLABORATOR) {
58
71
  let collaborator = collaborators.find(item => {
59
72
  let email = name;
@@ -84,10 +84,9 @@ class BarGroup extends ChartComponent {
84
84
  } = chart.config;
85
85
  const theme = CHART_THEME_COLOR[globalTheme];
86
86
  const isGroup = type === CHART_TYPE.BAR_GROUP;
87
- const isStack = type === CHART_TYPE.BAR_STACK;
88
87
  const newData = this.getChartGroupData(data);
89
- const groupByColumn = this.getColumn(tables, table_id, column_groupby_column_key);
90
- const useSingleSelectColumnColor = (groupByColumn === null || groupByColumn === void 0 ? void 0 : groupByColumn.type) === CellType.SINGLE_SELECT && isStack && color_theme === STACK_AND_PIE_CHART_THEMES_OPTIONS.SINGLE_SELECT_COLUMN_COLORS;
88
+ const column_groupby_column = this.getColumn(tables, table_id, column_groupby_column_key);
89
+ const useSingleSelectColumnColor = (column_groupby_column === null || column_groupby_column === void 0 ? void 0 : column_groupby_column.type) === CellType.SINGLE_SELECT && color_theme === STACK_AND_PIE_CHART_THEMES_OPTIONS.SINGLE_SELECT_COLUMN_COLORS;
91
90
  let singleBarWidth, singleBarRadius;
92
91
  // y-axis label width:6 + 10
93
92
  const chartWidth = this.chart.width - 6 - 10;
@@ -147,7 +146,9 @@ class BarGroup extends ChartComponent {
147
146
  type: 'dodge',
148
147
  marginRatio: 0
149
148
  };
150
- this.setColorMap(data, chartColorTheme);
149
+
150
+ // use single select column color
151
+ useSingleSelectColumnColor ? this.setSingleSelectColorMap(data) : this.setColorMap(data, chartColorTheme);
151
152
  this.chart.interval().animate({
152
153
  // custom update animation
153
154
  update: {
@@ -163,8 +164,8 @@ class BarGroup extends ChartComponent {
163
164
  lineWidth: 1
164
165
  },
165
166
  position: type === CHART_TYPE.BAR_STACK ? 'middle' : ''
166
- }).position('name*value').size(singleBarWidth).color('group_name*group_color', (group_name, group_color) => {
167
- return useSingleSelectColumnColor ? group_color : this.colorMap[group_name] || CHART_STYLE_COLORS[0];
167
+ }).position('name*value').size(singleBarWidth).color('group_name', group_name => {
168
+ return this.colorMap[group_name] || CHART_STYLE_COLORS[0];
168
169
  }).tooltip('name*value*group_name*raw_name', (name, value, group_name, raw_name) => {
169
170
  return {
170
171
  title: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name,
@@ -197,7 +198,7 @@ class BarGroup extends ChartComponent {
197
198
  if (isGroup) {
198
199
  this.formatDataByName(data);
199
200
  }
200
- this.setToolTip(isGroup, summaryColumn, y_axis_summary_method);
201
+ this.setToolTip(isGroup, summaryColumn, y_axis_summary_method, useSingleSelectColumnColor);
201
202
  isFunction(customRender) && customRender(this.chart);
202
203
  this.setNameLabelAndTooltip(theme, this.labelCount);
203
204
  this.setValueLabel(theme);
@@ -465,6 +465,13 @@ export default class ChartComponent extends Component {
465
465
  }, {});
466
466
  this.colorMap = colorMap;
467
467
  };
468
+ this.setSingleSelectColorMap = data => {
469
+ const colorMap = {};
470
+ data.forEach(item => {
471
+ colorMap[item.group_name] = item.group_color || item.color;
472
+ });
473
+ this.colorMap = colorMap;
474
+ };
468
475
  this.formatDataByName = data => {
469
476
  const formattedItems = {};
470
477
  data.forEach(item => {
@@ -478,7 +485,7 @@ export default class ChartComponent extends Component {
478
485
  });
479
486
  this.formatedDataByName = formattedItems;
480
487
  };
481
- this.getToolTipSettings = (isGroup, summaryColumn, y_axis_summary_method) => {
488
+ this.getToolTipSettings = (isGroup, summaryColumn, y_axis_summary_method, useSingleSelectColumnColor) => {
482
489
  const obj = {
483
490
  showMarkers: false,
484
491
  containerTpl: "<div class=\"g2-tooltip\">\n <div class=\"g2-tooltip-title\">{title}</div>\n <ul class=\"g2-tooltip-list\"></ul>\n </div>",
@@ -537,7 +544,7 @@ export default class ChartComponent extends Component {
537
544
  const name = activeItem.data.name;
538
545
  return this.formatedDataByName[name].map(item => {
539
546
  return {
540
- color: this.colorMap[item.group_name] || CHART_STYLE_COLORS[0],
547
+ color: useSingleSelectColumnColor ? item.group_color : this.colorMap[item.group_name] || CHART_STYLE_COLORS[0],
541
548
  data: item,
542
549
  name: !item.group_name && typeof item.group_name !== 'number' ? intl.get(EMPTY_NAME) : item.group_name,
543
550
  title: item.name,
@@ -548,8 +555,8 @@ export default class ChartComponent extends Component {
548
555
  }
549
556
  return obj;
550
557
  };
551
- this.setToolTip = (isGroup, summaryColumn, y_axis_summary_method) => {
552
- const settings = this.getToolTipSettings(isGroup, summaryColumn, y_axis_summary_method);
558
+ this.setToolTip = (isGroup, summaryColumn, y_axis_summary_method, useSingleSelectColumnColor) => {
559
+ const settings = this.getToolTipSettings(isGroup, summaryColumn, y_axis_summary_method, useSingleSelectColumnColor);
553
560
  this.chart.tooltip(settings);
554
561
  };
555
562
  this.setToolTipForLine = () => {
@@ -71,9 +71,8 @@ class HorizontalBarGroup extends HorizontalComponent {
71
71
  color_theme
72
72
  } = chart.config;
73
73
  const isGroup = type === CHART_TYPE.HORIZONTAL_GROUP_BAR;
74
- const isStack = type === CHART_TYPE.STACKED_HORIZONTAL_BAR;
75
74
  const groupByColumn = this.getColumn(tables, table_id, column_groupby_column_key);
76
- const useSingleSelectColumnColor = (groupByColumn === null || groupByColumn === void 0 ? void 0 : groupByColumn.type) === CellType.SINGLE_SELECT && isStack && color_theme === STACK_AND_PIE_CHART_THEMES_OPTIONS.SINGLE_SELECT_COLUMN_COLORS;
75
+ const useSingleSelectColumnColor = (groupByColumn === null || groupByColumn === void 0 ? void 0 : groupByColumn.type) === CellType.SINGLE_SELECT && color_theme === STACK_AND_PIE_CHART_THEMES_OPTIONS.SINGLE_SELECT_COLUMN_COLORS;
77
76
  const newData = this.getChartGroupData(data);
78
77
  let singleBarWidth, singleBarRadius;
79
78
  // y-axis label width:(6 + 10)
@@ -99,7 +98,9 @@ class HorizontalBarGroup extends HorizontalComponent {
99
98
  type: 'dodge',
100
99
  marginRatio: 0
101
100
  };
102
- this.setColorMap(data, chartColorTheme);
101
+
102
+ // use single select column color
103
+ useSingleSelectColumnColor ? this.setSingleSelectColorMap(data) : this.setColorMap(data, chartColorTheme);
103
104
  this.chart.interval().animate({
104
105
  // custom update animation
105
106
  update: {
@@ -114,8 +115,8 @@ class HorizontalBarGroup extends HorizontalComponent {
114
115
  stroke: '#fff',
115
116
  lineWidth: 1
116
117
  }
117
- }).position('name*value').size(singleBarWidth).color('group_name*group_color', (group_name, group_color) => {
118
- return useSingleSelectColumnColor ? group_color : this.colorMap[group_name] || CHART_STYLE_COLORS[0];
118
+ }).position('name*value').size(singleBarWidth).color('group_name', group_name => {
119
+ return this.colorMap[group_name] || CHART_STYLE_COLORS[0];
119
120
  }).tooltip('name*value*group_name*raw_name', (name, value, group_name, raw_name) => {
120
121
  return {
121
122
  title: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name,
@@ -23,6 +23,7 @@ class OneDimensionTableNoNumericColumns extends PureComponent {
23
23
  name: groupName
24
24
  } = groupbyColumn;
25
25
  const isCount = summary_type === CHART_SUMMARY_TYPE.COUNT;
26
+ this.isCount = isCount;
26
27
  const columnName = isCount ? intl.get('Amount') : this.getColumnName();
27
28
  const {
28
29
  rowIdx: selectRowIdx,
@@ -63,7 +64,7 @@ class OneDimensionTableNoNumericColumns extends PureComponent {
63
64
  return '';
64
65
  };
65
66
  this.toggleRecords = (cell, selectedCell) => {
66
- if (window.isMobile) return;
67
+ if (window.isMobile || !this.isCount) return;
67
68
  const {
68
69
  rowIdx: selectedRowIdx,
69
70
  cellIdx: selectedCellIdx
@@ -76,8 +77,17 @@ class OneDimensionTableNoNumericColumns extends PureComponent {
76
77
  this.props.toggleRecords(cell, selectedCell);
77
78
  };
78
79
  this.onClickTotals = (recordsList, selectedCell) => {
80
+ if (!this.isCount) return; // only count support show details
79
81
  if (window.isMobile) return;
80
- const rows = recordsList.flat();
82
+ const rows = recordsList.reduce((acc, cur) => {
83
+ const {
84
+ rows
85
+ } = cur;
86
+ if (Array.isArray(rows)) {
87
+ acc = acc.concat(rows);
88
+ }
89
+ return acc;
90
+ }, []);
81
91
  const total = rows.length;
82
92
  this.toggleRecords({
83
93
  rows,
@@ -185,6 +195,10 @@ class OneDimensionTableNoNumericColumns extends PureComponent {
185
195
  'pivot-empty-cell': !isValidSummaryDisplayValue,
186
196
  'selected-pivot-cell': isSelectTotal
187
197
  }),
198
+ onClick: () => this.onClickTotals(pivotColumnCells, {
199
+ rowIdx: pivot_rows.length,
200
+ cellIdx: 0
201
+ }),
188
202
  title: isValidSummaryDisplayValue ? summaryDisplayValue : ''
189
203
  }, isValidSummaryDisplayValue ? summaryDisplayValue : /*#__PURE__*/React.createElement("i", null), /*#__PURE__*/React.createElement("span", {
190
204
  className: classnames({
@@ -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;
@@ -83,6 +99,7 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
83
99
  total
84
100
  }, selectedCell);
85
101
  };
102
+ // click records only support summary_type is COUNT
86
103
  this.renderRows = () => {
87
104
  const {
88
105
  result,
@@ -108,13 +125,20 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
108
125
  const pivotRowsLen = Array.isArray(pivot_rows) ? pivot_rows.length : 0;
109
126
  let pivotColumnCells = [];
110
127
  const isSelectRowTotalCellRight = selectRowIdx === pivotRowsLen && selectedCellIdx === 0;
128
+ let lastRowTotal = 0;
129
+ let lastRows = [];
111
130
  return /*#__PURE__*/React.createElement("tbody", null, pivotRowsLen > 0 && pivot_rows.map((rowItem, rowIdx) => {
112
131
  const {
113
132
  name,
114
133
  total,
115
134
  rows
116
135
  } = rowItem;
136
+ lastRows.push(rows);
117
137
  const isSelectedRowNameRight = selectRowIdx === rowIdx && selectedCellIdx === 0;
138
+ const isSelectedTotalCell = selectRowIdx === rowIdx && selectedCellIdx === (pivot_columns === null || pivot_columns === void 0 ? void 0 : pivot_columns.length);
139
+ const isSelectedTotalCellTop = selectRowIdx - 1 === rowIdx && selectedCellIdx === (pivot_columns === null || pivot_columns === void 0 ? void 0 : pivot_columns.length);
140
+ const isSelectedTotalCellLeft = selectRowIdx === rowIdx && selectedCellIdx - 1 === (pivot_columns === null || pivot_columns === void 0 ? void 0 : pivot_columns.length) - 1;
141
+ let rowTotal = 0;
118
142
  if (!Array.isArray(pivot_columns)) {
119
143
  pivotColumnCells[rowIdx] = rowItem.rows || [];
120
144
  }
@@ -137,6 +161,7 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
137
161
  key
138
162
  } = columnMap;
139
163
  const column = chartTableColumns.find(item => item.key === key);
164
+ rowTotal = this.getRowTotal(rowTotal, total[key]);
140
165
  const displayValue = BaseUtils.getSummaryValueDisplayString(column, total[key], this.summaryColumnsMethodMap[key]);
141
166
  const isValidDisplayValue = BaseUtils.isValidValue(displayValue, display_empty);
142
167
  if (Array.isArray(rows) && rows.length > 0) {
@@ -153,22 +178,29 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
153
178
  'selected-pivot-cell-top': isSelectedCellTop,
154
179
  'selected-pivot-cell-left': isSelectedCellLeft
155
180
  }),
156
- key: "table-cell-".concat(cellIdx),
157
- onClick: () => this.toggleRecords({
158
- rows,
159
- name: rowItem === null || rowItem === void 0 ? void 0 : rowItem.name,
160
- total: total[key]
161
- }, {
162
- rowIdx,
163
- cellIdx
164
- }),
181
+ key: "table-cell-".concat(cellIdx)
182
+ // onClick={() => this.toggleRecords({ rows, name: rowItem?.name, total: total[key] }, { rowIdx, cellIdx })}
183
+ ,
165
184
  title: isValidDisplayValue ? displayValue : ''
166
185
  }, isValidDisplayValue ? displayValue : /*#__PURE__*/React.createElement("i", null), /*#__PURE__*/React.createElement("span", {
167
186
  className: classnames({
168
187
  'selected-pivot-cell-border': isSelectedCell
169
188
  })
170
189
  }));
171
- }));
190
+ }), display_total && /*#__PURE__*/React.createElement("td", {
191
+ className: classnames('pivot-cell', {
192
+ 'selected-pivot-cell': isSelectedTotalCell,
193
+ 'selected-pivot-cell-top': isSelectedTotalCellTop,
194
+ 'selected-pivot-cell-left': isSelectedTotalCellLeft
195
+ })
196
+ // onClick={() => this.toggleRecords({ rows, name: rowItem?.name, total: rowTotal }, { rowIdx })}
197
+ ,
198
+ title: rowTotal ? rowTotal : 0
199
+ }, rowTotal ? rowTotal : /*#__PURE__*/React.createElement("i", null, "0"), /*#__PURE__*/React.createElement("span", {
200
+ className: classnames({
201
+ 'selected-pivot-cell-border': isSelectedTotalCell
202
+ })
203
+ })));
172
204
  }), display_total && /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("td", {
173
205
  className: classnames('pivot-column-total', {
174
206
  'selected-pivot-cell-left': isSelectRowTotalCellRight
@@ -181,27 +213,30 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
181
213
  const isValidTotalDisplayValue = BaseUtils.isValidValue(totalDisplayValue, display_empty);
182
214
  const isSelectRowTotalCell = selectRowIdx === pivot_rows.length && selectedCellIdx === index;
183
215
  const isSelectRowTotalCellLeft = selectRowIdx === pivot_rows.length && selectedCellIdx - 1 === index;
216
+ lastRowTotal = this.getRowTotal(lastRowTotal, pivotColumnTotal);
184
217
  return /*#__PURE__*/React.createElement("td", {
185
218
  className: classnames('pivot-cell', {
186
219
  'pivot-empty-cell': !isValidTotalDisplayValue,
187
220
  'selected-pivot-cell': isSelectRowTotalCell,
188
221
  'selected-pivot-cell-left': isSelectRowTotalCellLeft
189
222
  }),
190
- key: "total-cell-".concat(index),
191
- onClick: () => this.toggleRecords({
192
- rows: pivotColumnCell,
193
- total: pivot_columns_total[c.key]
194
- }, {
195
- rowIdx: pivot_rows.length,
196
- cellIdx: index
197
- }),
223
+ key: "total-cell-".concat(index)
224
+ // onClick={() => this.toggleRecords({ rows: pivotColumnCell, total: pivot_columns_total[c.key] }, { rowIdx: pivot_rows.length, cellIdx: index })}
225
+ ,
198
226
  title: totalDisplayValue
199
227
  }, isValidTotalDisplayValue ? totalDisplayValue : /*#__PURE__*/React.createElement("i", null), /*#__PURE__*/React.createElement("span", {
200
228
  className: classnames({
201
229
  'selected-pivot-cell-border': isSelectRowTotalCell
202
230
  })
203
231
  }));
204
- })));
232
+ }), /*#__PURE__*/React.createElement("td", {
233
+ className: classnames('pivot-cell', {
234
+ 'pivot-empty-cell': !BaseUtils.isValidValue(lastRowTotal, display_empty)
235
+ })
236
+ // onClick={() => this.toggleRecords({ rows: lastRows, total: lastRowTotal }, { rowIdx: pivot_rows.length, cellIdx: pivot_columns?.length })}
237
+ ,
238
+ title: lastRowTotal
239
+ }, BaseUtils.isValidValue(lastRowTotal, display_empty) ? lastRowTotal : /*#__PURE__*/React.createElement("i", null))));
205
240
  };
206
241
  this.init(_props);
207
242
  }
@@ -103,6 +103,11 @@ class PivotTableDisplayName extends React.Component {
103
103
  const {
104
104
  collaborators
105
105
  } = this.state;
106
+
107
+ // link formula column is collaborator
108
+ if (type === CellType.LINK_FORMULA && (data === null || data === void 0 ? void 0 : data.array_type) === CellType.COLLABORATOR) {
109
+ type = CellType.COLLABORATOR;
110
+ }
106
111
  let displayName;
107
112
  switch (type) {
108
113
  case CellType.SINGLE_SELECT:
@@ -147,9 +152,20 @@ class PivotTableDisplayName extends React.Component {
147
152
  const {
148
153
  original_name
149
154
  } = rowData || {};
150
- let validValue = Array.isArray(value) && value.length !== 0 ? value : [];
155
+ let validValue;
156
+ if (Array.isArray(value)) {
157
+ validValue = value;
158
+ } else if (value) {
159
+ validValue = [value];
160
+ } else {
161
+ validValue = [];
162
+ }
151
163
  if (original_name) {
152
- validValue = [original_name];
164
+ if (!Array.isArray(original_name)) {
165
+ validValue = [original_name];
166
+ } else {
167
+ validValue = original_name;
168
+ }
153
169
  }
154
170
  const unknowEmails = validValue.filter(email => !getCollaborator(collaborators, email));
155
171
 
@@ -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,12 +103,12 @@ 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
  };
111
110
  this.toggleRecords = (cell, selectedCell) => {
112
- if (window.isMobile) return;
111
+ if (window.isMobile || !this.isCount) return;
113
112
  const {
114
113
  rowIdx: selectedRowIdx,
115
114
  cellIdx: selectedCellIdx
@@ -122,7 +121,7 @@ class TwoDimensionTable extends PureComponent {
122
121
  this.props.toggleRecords(cell, selectedCell);
123
122
  };
124
123
  this.onClickTotals = (recordsList, selectedCell) => {
125
- if (window.isMobile) return;
124
+ if (window.isMobile || !this.isCount) return;
126
125
  const rows = recordsList.flat();
127
126
  const total = rows.length;
128
127
  this.toggleRecords({
@@ -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,
@@ -181,6 +186,7 @@ class TwoDimensionTable extends PureComponent {
181
186
  const tableTotalDisplayValue = BaseUtils.getSummaryValueDisplayString(summaryColumn, pivot_table_total, summaryMethod);
182
187
  const isValidTableTotalDisplayValue = BaseUtils.isValidValue(tableTotalDisplayValue, display_empty);
183
188
  const isCount = summary_type === CHART_SUMMARY_TYPE.COUNT;
189
+ this.isCount = isCount;
184
190
  const isCollaborator = groupbyColumn.type === CellType.COLLABORATOR;
185
191
  return /*#__PURE__*/React.createElement("tbody", null, pivotRowsLen > 0 && pivot_rows.map((rowItem, rowIdx) => {
186
192
  let {
@@ -199,8 +205,7 @@ class TwoDimensionTable extends PureComponent {
199
205
  if (!Array.isArray(pivot_columns)) {
200
206
  pivotColumnCells[rowIdx] = rowItem.rows || [];
201
207
  }
202
- const summaryDisplayValue = BaseUtils.getSummaryValueDisplayString(summaryColumn, total, summaryMethod);
203
- const isValidSummaryDisplayValue = BaseUtils.isValidValue(summaryDisplayValue, display_empty);
208
+ let rowTotal = 0;
204
209
  return /*#__PURE__*/React.createElement("tr", {
205
210
  key: 'table-row' + rowIdx
206
211
  }, /*#__PURE__*/React.createElement("td", {
@@ -222,6 +227,7 @@ class TwoDimensionTable extends PureComponent {
222
227
  if (isCount) {
223
228
  const displayValue = total;
224
229
  const isValidDisplayValue = BaseUtils.isValidValue(displayValue, display_empty);
230
+ rowTotal = this.getRowTotal(rowTotal, displayValue);
225
231
  if (c && Array.isArray(c.rows) && c.rows.length > 0) {
226
232
  pivotRowCells.push(...c.rows);
227
233
  if (pivotColumnCells[cellIdx]) {
@@ -262,6 +268,7 @@ class TwoDimensionTable extends PureComponent {
262
268
  const summaryCellColumn = summaryColumns === null || summaryColumns === void 0 ? void 0 : summaryColumns.find(item => item.key === summaryCellColumnKey);
263
269
  const displayValue = BaseUtils.getSummaryValueDisplayString(summaryCellColumn, summaryCell[1], summaryMethod);
264
270
  const isValidDisplayValue = BaseUtils.isValidValue(displayValue, display_empty);
271
+ rowTotal = this.getRowTotal(rowTotal, summaryCell[1]);
265
272
  return /*#__PURE__*/React.createElement("div", {
266
273
  key: "table-cell-".concat(cellIdx, "-").concat(idx),
267
274
  className: classnames('pivot-cell', {
@@ -278,7 +285,6 @@ class TwoDimensionTable extends PureComponent {
278
285
  }), !total && !(typeof total === 'number') && this.renderEmpty(summaryColumns, cellIdx)));
279
286
  }), display_total && /*#__PURE__*/React.createElement("td", {
280
287
  className: classnames('pivot-cell', {
281
- 'pivot-empty-cell': !isValidSummaryDisplayValue,
282
288
  'selected-pivot-cell': isSelectedTotalCell,
283
289
  'selected-pivot-cell-top': isSelectedTotalCellTop,
284
290
  'selected-pivot-cell-left': isSelectedTotalCellLeft
@@ -291,8 +297,8 @@ class TwoDimensionTable extends PureComponent {
291
297
  rowIdx,
292
298
  cellIdx: cells.length
293
299
  }),
294
- title: summaryDisplayValue
295
- }, isValidSummaryDisplayValue ? summaryDisplayValue : /*#__PURE__*/React.createElement("i", null), /*#__PURE__*/React.createElement("span", {
300
+ title: rowTotal
301
+ }, BaseUtils.isValidValue(rowTotal, display_empty) ? rowTotal : /*#__PURE__*/React.createElement("i", null), /*#__PURE__*/React.createElement("span", {
296
302
  className: classnames({
297
303
  'selected-pivot-cell-border': isSelectedTotalCell
298
304
  })
@@ -77,11 +77,11 @@ class Trend extends Component {
77
77
  } = data || {};
78
78
  let color, icon;
79
79
  if (type === TREND_TYPES.UP) {
80
- color = '#fa5757';
80
+ color = '#34aa95';
81
81
  icon = 'dtable-icon-up1';
82
82
  }
83
83
  if (type === TREND_TYPES.DOWN) {
84
- color = '#34aa95';
84
+ color = '#fa5757';
85
85
  icon = 'dtable-icon-down1';
86
86
  }
87
87
  if (type === TREND_TYPES.EQUAL) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sea-chart",
3
- "version": "0.0.90",
3
+ "version": "0.0.92",
4
4
  "main": "./dist/index.js",
5
5
  "dependencies": {
6
6
  "@antv/data-set": "0.11.8",