sea-chart 0.0.90 → 0.0.91

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
  }
@@ -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,
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
  }
@@ -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
  }
@@ -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,10 @@ 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
+
33
+ // currently just COMBINATION, if something wrong of MULTIPLE_SELECT happens find out, add more types here
34
+ const FORMAT_MULTIPLE_SELECT_CHART_TYPES = [CHART_TYPE.COMBINATION, CHART_TYPE.BAR_CUSTOM];
35
+ export const getFormattedLabel = (column, name, collaborators, chartType) => {
32
36
  let {
33
37
  type: columnType,
34
38
  data: columnData
@@ -49,6 +53,17 @@ export const getFormattedLabel = (column, name, collaborators) => {
49
53
  return optionName;
50
54
  }
51
55
  } else if (columnType === CellType.MULTIPLE_SELECT) {
56
+ if (FORMAT_MULTIPLE_SELECT_CHART_TYPES.includes(chartType)) {
57
+ const options = getColumnOptions(column);
58
+ let selectedOption = getOption(options, name);
59
+ let {
60
+ name: optionName,
61
+ color: optionColor
62
+ } = selectedOption || {};
63
+ // TODO:use option‘s color
64
+ // return { name: optionName, color: optionColor };
65
+ return optionName;
66
+ }
52
67
  // Return the array directly and process it in the rendering, file directly: src/view/wrapper/table/pivot-table-display-name.js
53
68
  if (Array.isArray(name)) {
54
69
  return 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
88
  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;
89
+ 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;
91
90
  let singleBarWidth, singleBarRadius;
92
91
  // y-axis label width:6 + 10
93
92
  const chartWidth = this.chart.width - 6 - 10;
@@ -197,7 +196,7 @@ class BarGroup extends ChartComponent {
197
196
  if (isGroup) {
198
197
  this.formatDataByName(data);
199
198
  }
200
- this.setToolTip(isGroup, summaryColumn, y_axis_summary_method);
199
+ this.setToolTip(isGroup, summaryColumn, y_axis_summary_method, useSingleSelectColumnColor);
201
200
  isFunction(customRender) && customRender(this.chart);
202
201
  this.setNameLabelAndTooltip(theme, this.labelCount);
203
202
  this.setValueLabel(theme);
@@ -478,7 +478,7 @@ export default class ChartComponent extends Component {
478
478
  });
479
479
  this.formatedDataByName = formattedItems;
480
480
  };
481
- this.getToolTipSettings = (isGroup, summaryColumn, y_axis_summary_method) => {
481
+ this.getToolTipSettings = (isGroup, summaryColumn, y_axis_summary_method, useSingleSelectColumnColor) => {
482
482
  const obj = {
483
483
  showMarkers: false,
484
484
  containerTpl: "<div class=\"g2-tooltip\">\n <div class=\"g2-tooltip-title\">{title}</div>\n <ul class=\"g2-tooltip-list\"></ul>\n </div>",
@@ -537,7 +537,7 @@ export default class ChartComponent extends Component {
537
537
  const name = activeItem.data.name;
538
538
  return this.formatedDataByName[name].map(item => {
539
539
  return {
540
- color: this.colorMap[item.group_name] || CHART_STYLE_COLORS[0],
540
+ color: useSingleSelectColumnColor ? item.group_color : this.colorMap[item.group_name] || CHART_STYLE_COLORS[0],
541
541
  data: item,
542
542
  name: !item.group_name && typeof item.group_name !== 'number' ? intl.get(EMPTY_NAME) : item.group_name,
543
543
  title: item.name,
@@ -548,8 +548,8 @@ export default class ChartComponent extends Component {
548
548
  }
549
549
  return obj;
550
550
  };
551
- this.setToolTip = (isGroup, summaryColumn, y_axis_summary_method) => {
552
- const settings = this.getToolTipSettings(isGroup, summaryColumn, y_axis_summary_method);
551
+ this.setToolTip = (isGroup, summaryColumn, y_axis_summary_method, useSingleSelectColumnColor) => {
552
+ const settings = this.getToolTipSettings(isGroup, summaryColumn, y_axis_summary_method, useSingleSelectColumnColor);
553
553
  this.chart.tooltip(settings);
554
554
  };
555
555
  this.setToolTipForLine = () => {
@@ -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
  }
@@ -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,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
  })
@@ -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.91",
4
4
  "main": "./dist/index.js",
5
5
  "dependencies": {
6
6
  "@antv/data-set": "0.11.8",