sea-chart 0.0.88 → 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.
@@ -1,3 +1,4 @@
1
+ import _toaster from "dtable-ui-component/lib/toaster";
1
2
  import React, { Fragment } from 'react';
2
3
  import { Modal, ModalBody } from 'reactstrap';
3
4
  import { getTableById, getViewById, isArchiveView, getFormulaColumnsContainLinks, getViewShownColumns } from 'dtable-utils';
@@ -11,6 +12,7 @@ import ChartDataSQL from '../../utils/sql/chart-data-sql';
11
12
  import { getFilterConditions } from '../../utils/row-record-utils';
12
13
  import RowCard from '../row-card/row-card';
13
14
  import { CommonEventTypes } from '../../constants/common-constants';
15
+ import { getErrorMessage } from '../../utils';
14
16
  import './index.css';
15
17
  class StatisticRecordDialog extends React.Component {
16
18
  constructor(_props) {
@@ -52,7 +54,11 @@ class StatisticRecordDialog extends React.Component {
52
54
  results: rows
53
55
  } = res.data;
54
56
  this.processDrilledRows(rows);
55
- }).catch(error => new Error(error));
57
+ }).catch(error => {
58
+ const errMsg = getErrorMessage(error);
59
+ _toaster.danger(errMsg);
60
+ console.error(error);
61
+ });
56
62
  return;
57
63
  }
58
64
  const chartDataSQL = new ChartDataSQL({
@@ -69,7 +75,11 @@ class StatisticRecordDialog extends React.Component {
69
75
  results: rows
70
76
  } = res.data;
71
77
  this.processDrilledRows(rows);
72
- }).catch(error => new Error(error));
78
+ }).catch(error => {
79
+ const errMsg = getErrorMessage(error);
80
+ _toaster.danger(errMsg);
81
+ console.error(error);
82
+ });
73
83
  return;
74
84
  }
75
85
  this.processDrilledRows(rows);
@@ -297,6 +297,6 @@ export const groupAxisMap = {
297
297
  [CHART_TYPE.LINE_GROUP]: 'column_groupby_column_key',
298
298
  [CHART_TYPE.SCATTER]: 'column_groupby_column_key',
299
299
  [CHART_TYPE.MIRROR]: 'group_column_key',
300
- [CHART_TYPE.TABLE]: 'groupby_column_key'
300
+ [CHART_TYPE.TABLE]: 'column_groupby_column_key'
301
301
  };
302
302
  export { GEOLOCATION_FORMAT_CITY, GEOLOCATION_FORMAT_MAP, CHART_KEY, GENERIC_KEY, GENERIC_KEY_2_SIMILAR_KEYS, STYLE_COLORS, HORIZONTAL_ALIGN, HORIZONTAL_ALIGNS, HORIZONTAL_ALIGN_SHOW, CHART_TYPE, CHART_TYPE_SHOW, CHART_TYPES, CHART_TYPE_IMAGE, GEOLOCATION_GRANULARITY, GEOLOCATION_GRANULARITY_LIST, MAP_LEVEL, MUNICIPALITIES, regions, TABLE_DIMENSIONS };
@@ -227,10 +227,10 @@ const de = {
227
227
  "Transpose": "Transpose",
228
228
  "Comparison_mode": "Vergleichsmodus",
229
229
  "Yesterday_vs_the_day_before_yesterday": "Gestern vs. vorgestern",
230
- "Last_week_vs_the_week_before_last": "Letzte Woche vs. die Woche davor",
231
- "Last_month_vs_the_month_before_last": "Letzter Monat vs. der Monat davor",
232
- "Last_quarter_vs_the_quarter_before_last": "Letztes Quartal vs. das Quartal davor",
233
- "Last_year_vs_the_year_before_last": "Letztes Jahr vs. das Jahr davor",
230
+ "Last_week_vs_the_week_before_last": "Letzte Woche vs. Vorwoche",
231
+ "Last_month_vs_the_month_before_last": "Letzter Monat vs. Vormonat",
232
+ "Last_quarter_vs_the_quarter_before_last": "Letztes Quartal vs. Vorquartal",
233
+ "Last_year_vs_the_year_before_last": "Letztes Jahr vs. Vorjahr",
234
234
  "Last_7_days_vs_previous_7_days": "Letzte 7 Tage vs. 7 Tage davor",
235
235
  "Last_30_days_vs_previous_30_days": "Letzte 30 Tage vs. 30 Tage davor",
236
236
  "The_year_before_last": "Das vorletzte Jahr",
@@ -249,6 +249,7 @@ const de = {
249
249
  "Count_description": "Einträge basierend auf den Dateneinstellungen zählen",
250
250
  "Display_empty_when_data_is_zero": "Wert 0 als leeren Wert anzeigen",
251
251
  "Use_default_color": "Standardfarbe verwenden",
252
- "Use_colors_in_single_select_solumn": "Verwenden Sie Farben in einer einzelnen Auswahlspalte"
252
+ "Use_colors_in_single_select_solumn": "Verwenden Sie Farben in einer einzelnen Auswahlspalte",
253
+ "Search_records": "Einträge suchen"
253
254
  };
254
255
  export default de;
@@ -249,6 +249,7 @@ const en = {
249
249
  "Count_description": "Count the number of records based on data settings",
250
250
  "Display_empty_when_data_is_zero": "Display empty when data is zero",
251
251
  "Use_default_color": "Use default color",
252
- "Use_colors_in_single_select_solumn": "Use colors in single select column"
252
+ "Use_colors_in_single_select_solumn": "Use colors in single select column",
253
+ "Search_records": "Search records"
253
254
  };
254
255
  export default en;
@@ -249,6 +249,7 @@ const es = {
249
249
  "Count_description": "Count the number of records based on data settings",
250
250
  "Display_empty_when_data_is_zero": "Display empty when data is zero",
251
251
  "Use_default_color": "Use default color",
252
- "Use_colors_in_single_select_solumn": "Use colors in single select column"
252
+ "Use_colors_in_single_select_solumn": "Use colors in single select column",
253
+ "Search_records": "Search records"
253
254
  };
254
255
  export default es;
@@ -229,8 +229,8 @@ const fr = {
229
229
  "Yesterday_vs_the_day_before_yesterday": "Hier vs. avant-hier",
230
230
  "Last_week_vs_the_week_before_last": "La semaine dernière vs. la semaine précédente",
231
231
  "Last_month_vs_the_month_before_last": "Le mois dernier vs. le mois précédent",
232
- "Last_quarter_vs_the_quarter_before_last": "Dernier trimestre vs. le trimestre précédent",
233
- "Last_year_vs_the_year_before_last": "Dernière année vs. l'année précédente",
232
+ "Last_quarter_vs_the_quarter_before_last": "Le dernier trimestre vs. le trimestre précédent",
233
+ "Last_year_vs_the_year_before_last": "La dernière année vs. l'année précédente",
234
234
  "Last_7_days_vs_previous_7_days": "7 derniers jours vs. 7 jours précédents",
235
235
  "Last_30_days_vs_previous_30_days": "30 derniers jours vs. 30 jours précédents",
236
236
  "The_year_before_last": "L'année précédente",
@@ -249,6 +249,7 @@ const fr = {
249
249
  "Count_description": "Compter les enregistrements basé sur les paramètres de données",
250
250
  "Display_empty_when_data_is_zero": "Afficher la valeur 0 comme valeur vide",
251
251
  "Use_default_color": "Utiliser la couleur par défaut",
252
- "Use_colors_in_single_select_solumn": "Utiliser les couleurs dans une colonne de sélection unique"
252
+ "Use_colors_in_single_select_solumn": "Utiliser les couleurs dans une colonne de sélection unique",
253
+ "Search_records": "Rechercher des enregistrements"
253
254
  };
254
255
  export default fr;
@@ -249,6 +249,7 @@ const pt = {
249
249
  "Count_description": "Count the number of records based on data settings",
250
250
  "Display_empty_when_data_is_zero": "Display empty when data is zero",
251
251
  "Use_default_color": "Use default color",
252
- "Use_colors_in_single_select_solumn": "Use colors in single select column"
252
+ "Use_colors_in_single_select_solumn": "Use colors in single select column",
253
+ "Search_records": "Search records"
253
254
  };
254
255
  export default pt;
@@ -249,6 +249,7 @@ const ru = {
249
249
  "Count_description": "Count the number of records based on data settings",
250
250
  "Display_empty_when_data_is_zero": "Display empty when data is zero",
251
251
  "Use_default_color": "Use default color",
252
- "Use_colors_in_single_select_solumn": "Use colors in single select column"
252
+ "Use_colors_in_single_select_solumn": "Use colors in single select column",
253
+ "Search_records": "Search records"
253
254
  };
254
255
  export default ru;
@@ -249,6 +249,7 @@ const zh_CN = {
249
249
  "Count_description": "根据数据设置计算记录数量",
250
250
  "Display_empty_when_data_is_zero": "数据为零时留空",
251
251
  "Use_default_color": "使用默认颜色",
252
- "Use_colors_in_single_select_solumn": "使用列中的选项颜色"
252
+ "Use_colors_in_single_select_solumn": "使用列中的选项颜色",
253
+ "Search_records": "搜索记录"
253
254
  };
254
255
  export default zh_CN;
@@ -33,12 +33,13 @@ class StacksSettings extends Component {
33
33
  currentSelectedOptions
34
34
  } = this.state;
35
35
  if (!Array.isArray(y_axises) || !y_axises[index]) return;
36
-
37
36
  // batch delete current selected options when "deleteStackNumericColumn"
38
- currentSelectedOptions.forEach(o => {
39
- o[index] && this.removeCurrentSelectedOptions(o[index], index);
40
- });
41
- this.setCurrentSelectedOptions();
37
+ if (currentSelectedOptions) {
38
+ currentSelectedOptions.forEach(o => {
39
+ o[index] && this.removeCurrentSelectedOptions(o[index], index);
40
+ });
41
+ this.setCurrentSelectedOptions();
42
+ }
42
43
  let updatedStacks = [...y_axises];
43
44
  updatedStacks.splice(index, 1);
44
45
  if (updatedStacks.length === 0) {
@@ -55,6 +56,7 @@ class StacksSettings extends Component {
55
56
  const {
56
57
  currentSelectedOptions
57
58
  } = this.state;
59
+ if (!currentSelectedOptions) return numericColumnsOptions;
58
60
  return numericColumnsOptions.filter(option => {
59
61
  const i = currentSelectedOptions.findIndex(o => {
60
62
  return Object.values(o)[0] && Object.values(o)[0].key === option.column.key;
@@ -77,6 +79,7 @@ class StacksSettings extends Component {
77
79
  } = updatedStack;
78
80
  let updatedNumericColumns = column_groupby_numeric_columns ? [...column_groupby_numeric_columns] : [];
79
81
  const availableOptions = this.getAvailableNumericColumns();
82
+ if (!availableOptions.length) return;
80
83
  const newNumericColumnKey = availableOptions[0].value;
81
84
  updatedNumericColumns.push({
82
85
  column_key: newNumericColumnKey,
@@ -99,7 +102,11 @@ class StacksSettings extends Component {
99
102
  const {
100
103
  y_axises
101
104
  } = chart.config;
102
- if (columnOption !== prevColumnOption) {
105
+ if (!prevColumnOption) {
106
+ this.addCurrentSelectedOptions(columnOption.column, currentAxisesIndex);
107
+ this.setCurrentSelectedOptions();
108
+ }
109
+ if (columnOption !== prevColumnOption && prevColumnOption) {
103
110
  // do not need to use "currentAxisesIndex" when delete cause every option is unique , "currentAxisesIndex" was used to batch delete "column_groupby_numeric_columns"
104
111
  // need "currentAxisesIndex" to identical the stack index
105
112
  this.removeCurrentSelectedOptions(prevColumnOption.column, currentAxisesIndex);
@@ -167,9 +174,10 @@ class StacksSettings extends Component {
167
174
  });
168
175
  };
169
176
  this.addCurrentSelectedOptions = (column, currentAxisesIndex) => {
170
- const {
177
+ let {
171
178
  currentSelectedOptions
172
179
  } = this.state;
180
+ if (!currentSelectedOptions) currentSelectedOptions = [];
173
181
  const newValue = this.newValue || [...currentSelectedOptions];
174
182
  newValue.push({
175
183
  [currentAxisesIndex]: column
@@ -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
  }
@@ -104,7 +104,7 @@ class NumericSummaryItem extends Component {
104
104
  if (currentSelectedOptions) {
105
105
  [selectedColumnOption, availableOptions] = this.getAvailableOptions();
106
106
  } else {
107
- selectedColumnOption = numericColumnOptions.find(option => option.value.key === column_key);
107
+ selectedColumnOption = numericColumnOptions.find(option => option.value.key === column_key || option.value === column_key);
108
108
  availableOptions = numericColumnOptions;
109
109
  }
110
110
  const selectedSummaryMethodOption = this.summaryMethodOptions.find(option => option.value === summary_method);
@@ -402,6 +402,10 @@ class YAxisGroupSettings extends Component {
402
402
  column_groupby_date_granularity,
403
403
  column_groupby_geolocation_granularity
404
404
  } = chart.config;
405
+
406
+ // if user do not select Single Numeric Column, then do not use it as the first config of multiple numeric column
407
+ const hasSingleNumericColumnConfig = !!(y_axis_summary_column_key && y_axis_summary_method);
408
+ const hasMultipleNumericColumnsConfig = column_groupby_multiple_numeric_column;
405
409
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FormGroup, {
406
410
  className: "sea-chart-parameter-item"
407
411
  }, /*#__PURE__*/React.createElement(Label, null, label), /*#__PURE__*/React.createElement(_DTableSelect, {
@@ -410,7 +414,9 @@ class YAxisGroupSettings extends Component {
410
414
  value: selectedTypeOption,
411
415
  onChange: this.onGroupTypeChange,
412
416
  options: this.groupTypeOptions
413
- })), y_axis_summary_type === CHART_SUMMARY_TYPE.ADVANCED && (column_groupby_multiple_numeric_column ? /*#__PURE__*/React.createElement(NumericSummaryItem, {
417
+ })),
418
+ // multiple but has single selected numeric column as the first config item
419
+ hasMultipleNumericColumnsConfig && (hasSingleNumericColumnConfig ? /*#__PURE__*/React.createElement(NumericSummaryItem, {
414
420
  index: 0,
415
421
  value: {
416
422
  column_key: y_axis_summary_column_key,
@@ -420,7 +426,9 @@ class YAxisGroupSettings extends Component {
420
426
  numericColumnOptions: this.numericColumnOptions,
421
427
  onColumnOptionChange: this.onGroupbyNumericColumnChange,
422
428
  onSummaryMethodChange: this.onSummaryMethodChange
423
- }) : /*#__PURE__*/React.createElement(SummaryMethodSettings, {
429
+ }) : null),
430
+ // single selected numeric columns
431
+ !hasMultipleNumericColumnsConfig && hasSingleNumericColumnConfig && /*#__PURE__*/React.createElement(SummaryMethodSettings, {
424
432
  value: {
425
433
  column_key: y_axis_summary_column_key,
426
434
  summary_method: y_axis_summary_method
@@ -429,7 +437,7 @@ class YAxisGroupSettings extends Component {
429
437
  numericColumnOptions: this.numericColumnOptions,
430
438
  onColumnOptionChange: option => this.onGroupbyNumericColumnChange(option, 0),
431
439
  onSummaryMethodChange: option => this.onSummaryMethodChange(option, 0)
432
- })), this.renderColumnGroupbyMultipleNumericColumn(), (!column_groupby_multiple_numeric_column && y_axis_summary_type === CHART_SUMMARY_TYPE.ADVANCED || y_axis_summary_type === CHART_SUMMARY_TYPE.COUNT) && !this.isMapChart && /*#__PURE__*/React.createElement(Groupby, {
440
+ }), this.renderColumnGroupbyMultipleNumericColumn(), (!column_groupby_multiple_numeric_column && y_axis_summary_type === CHART_SUMMARY_TYPE.ADVANCED || y_axis_summary_type === CHART_SUMMARY_TYPE.COUNT) && !this.isMapChart && /*#__PURE__*/React.createElement(Groupby, {
433
441
  label: intl.get('Group_by'),
434
442
  tables: tables,
435
443
  selectedTableId: table_id,
@@ -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
  }
@@ -240,7 +240,6 @@ async function calculateTwoDimensionTable(chart, value, _ref2) {
240
240
  return calculateOneDimensionTable(chart, value);
241
241
  }
242
242
  const isRowGroupbyColumnDataAsAnArray = isArrayCellValue(rowGroupbyColumn);
243
- const summaryColumn = getTableColumnByKey(table, summary_column_key);
244
243
  const statRows = await getViewRows(view, table);
245
244
  const formulaRows = await getTableFormulaResults(table, statRows);
246
245
  let pivot_columns = [];
@@ -281,10 +280,44 @@ async function calculateTwoDimensionTable(chart, value, _ref2) {
281
280
  }
282
281
  }
283
282
  });
283
+ let summaryColumn = null;
284
+ if (summary_column_key) {
285
+ summaryColumn = getTableColumnByKey(table, summary_column_key);
286
+ }
287
+
288
+ // Single field
284
289
  let {
285
290
  pivot_columns_total,
286
291
  pivot_table_total
287
- } = 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
+ }
288
321
  BaseUtils.sortCharts(pivot_rows, groupbyColumn, 'name');
289
322
  BaseUtils.sortCharts(pivot_columns, rowGroupbyColumn, 'key');
290
323
 
@@ -314,7 +347,7 @@ async function calculateTwoDimensionTable(chart, value, _ref2) {
314
347
  pivot_table_total,
315
348
  formulaRows,
316
349
  dimensions: TABLE_DIMENSIONS.TWO,
317
- summary_columns: [summaryColumn, ...(summary_columns === null || summary_columns === void 0 ? void 0 : summary_columns.map(item => getTableColumnByKey(table, item.column_key)))],
350
+ summary_columns: getAllSummaryColumns(summaryColumn, summary_columns, table),
318
351
  isSingleNumericColumn: !summary_columns.length ? 'true' : 'false'
319
352
  };
320
353
  }
@@ -526,6 +559,7 @@ function updateTwoDimensionRows(pivot_rows, pivot_columns, index, name, row, isC
526
559
  function getTwoDimensionTotal(summaryColumn, summary_type, summary_method, formula_rows) {
527
560
  let pivot_rows = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
528
561
  let pivot_columns = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : [];
562
+ let index = arguments.length > 6 ? arguments[6] : undefined;
529
563
  let pivot_columns_total = {};
530
564
  let pivot_table_total = 0;
531
565
  let dateColumnsTotalArr = [];
@@ -548,7 +582,7 @@ function getTwoDimensionTotal(summaryColumn, summary_type, summary_method, formu
548
582
  let {
549
583
  rows
550
584
  } = cells[key];
551
- 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);
552
586
  if (isSummaryDateColumn) {
553
587
  if (subTotal === 0) {
554
588
  cells[key].total = 0;
@@ -561,9 +595,9 @@ function getTwoDimensionTotal(summaryColumn, summary_type, summary_method, formu
561
595
  } else {
562
596
  if (Array.isArray(subTotal)) {
563
597
  cells[key].total = subTotal;
564
- total += subTotal[0][1] ? subTotal[0][1] - 0 : 0;
598
+ total += subTotal[index][1] ? subTotal[index][1] - 0 : 0;
565
599
  let columnTotal = pivot_columns_total[key] ? pivot_columns_total[key] : 0;
566
- columnTotal += subTotal[0][1] ? subTotal[0][1] - 0 : 0;
600
+ columnTotal += subTotal[index][1] ? subTotal[index][1] - 0 : 0;
567
601
  pivot_columns_total[key] = columnTotal;
568
602
  } else {
569
603
  cells[key].total = subTotal;
@@ -620,6 +654,7 @@ function getTotal(summary_column, summary_type, summary_method) {
620
654
  let rows = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
621
655
  let formula_rows = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
622
656
  let oldTotal = arguments.length > 5 ? arguments[5] : undefined;
657
+ let index = arguments.length > 6 ? arguments[6] : undefined;
623
658
  const summary_column_key = summary_column ? summary_column.key : '';
624
659
  const summary_column_type = summary_column ? summary_column.type : '';
625
660
  const rowsLength = rows.length;
@@ -651,7 +686,7 @@ function getTotal(summary_column, summary_type, summary_method) {
651
686
  total++;
652
687
  }
653
688
  });
654
- total = getTotalByType(oldTotal, total);
689
+ total = getTotalByType(oldTotal, total, index);
655
690
  return total;
656
691
  }
657
692
  if (summary_column && isDateColumn(summary_column)) {
@@ -709,10 +744,10 @@ function getTotal(summary_column, summary_type, summary_method) {
709
744
  }
710
745
  });
711
746
  if (summary_method === 'Sum') {
712
- total = getTotalByType(oldTotal, Number.parseFloat(sum.toFixed(8)));
747
+ total = getTotalByType(oldTotal, Number.parseFloat(sum.toFixed(8)), index);
713
748
  } else if (summary_method === 'Mean') {
714
749
  const val = validNumbersCount === 0 ? 0 : Number.parseFloat((sum / validNumbersCount).toFixed(8));
715
- total = getTotalByType(oldTotal, val);
750
+ total = getTotalByType(oldTotal, val, index);
716
751
  }
717
752
  break;
718
753
  }
@@ -745,15 +780,15 @@ function getTotal(summary_column, summary_type, summary_method) {
745
780
  let formulaRow = formula_rows[result._id];
746
781
  if (formulaRow) {
747
782
  if (formulaRow[summary_column_key] && typeof formulaRow[summary_column_key] === 'object') {
748
- total = getTotalByType(oldTotal, formulaRow[summary_column_key][0]);
783
+ total = getTotalByType(oldTotal, formulaRow[summary_column_key][0], index);
749
784
  } else {
750
- getTotalByType(oldTotal, formulaRow[summary_column_key]);
785
+ getTotalByType(oldTotal, formulaRow[summary_column_key], index);
751
786
  }
752
787
  } else {
753
- total = getTotalByType(oldTotal, null);
788
+ total = getTotalByType(oldTotal, null, index);
754
789
  }
755
790
  } else {
756
- total = getTotalByType(oldTotal, result[summary_column_key]);
791
+ total = getTotalByType(oldTotal, result[summary_column_key], index);
757
792
  }
758
793
  }
759
794
  break;
@@ -767,7 +802,7 @@ function getTotal(summary_column, summary_type, summary_method) {
767
802
  }
768
803
  // formula_rows result can be '#VALUE!'
769
804
  if (total === '#VALUE!') {
770
- total = getTotalByType(oldTotal, 0);
805
+ total = getTotalByType(oldTotal, 0, index);
771
806
  }
772
807
  return total || 0;
773
808
  }
@@ -817,17 +852,31 @@ function getDateMaxOrMinTotal(dateArr, type) {
817
852
  dateIndex = list.indexOf(dateValue);
818
853
  return dateArr[dateIndex];
819
854
  }
820
- function getTotalByType(oldTotal, value) {
855
+ function getTotalByType(oldTotal, value, index) {
821
856
  let newTotal = '';
822
857
  if (Array.isArray(oldTotal)) {
823
858
  newTotal = JSON.parse(JSON.stringify(oldTotal));
824
- newTotal[0][1] = value;
859
+ newTotal[index][1] = value;
825
860
  } else {
826
861
  newTotal = value;
827
862
  }
828
863
  return newTotal;
829
864
  }
830
865
 
866
+ // Get all non-empty summary columns
867
+ function getAllSummaryColumns(singleSummaryColumn, multipleSummaryColumns, table) {
868
+ const allSummaryColumns = [];
869
+ if (singleSummaryColumn) {
870
+ allSummaryColumns.push(singleSummaryColumn);
871
+ }
872
+ multipleSummaryColumns && multipleSummaryColumns.forEach(item => {
873
+ if (item === null || item === void 0 ? void 0 : item.column_key) {
874
+ allSummaryColumns.push(getTableColumnByKey(table, item.column_key));
875
+ }
876
+ });
877
+ return allSummaryColumns;
878
+ }
879
+
831
880
  // index
832
881
  function calculator(chart, value, _ref3) {
833
882
  let {
@@ -163,7 +163,10 @@ SQLStatisticsUtils.formatedTableSqlRows = (chart, sqlRows, chartSQLMap, columnMa
163
163
  if ((collaborators === null || collaborators === void 0 ? void 0 : collaborators.length) > 1) {
164
164
  newSqlRows.splice(index, 1);
165
165
  collaborators.forEach(collaborator => {
166
- const rowIndex = newSqlRows.findIndex(rows => rows[sqlGroupbyColumnKey][0] === collaborator);
166
+ const rowIndex = newSqlRows.findIndex(rows => {
167
+ var _rows$sqlGroupbyColum2;
168
+ return ((_rows$sqlGroupbyColum2 = rows[sqlGroupbyColumnKey]) === null || _rows$sqlGroupbyColum2 === void 0 ? void 0 : _rows$sqlGroupbyColum2[0]) === collaborator;
169
+ });
167
170
  if (rowIndex !== -1) {
168
171
  summarySQLColumnName2ColumnKeys.forEach(key => {
169
172
  let newKey = key;
@@ -37,6 +37,8 @@ export function getMapCanvasStyle(container, ratio) {
37
37
  };
38
38
  }
39
39
  export const getErrorMessage = err => {
40
+ // log error to locate problems
41
+ console.error(err);
40
42
  if (!err.response) {
41
43
  return intl.get('Network_error');
42
44
  }
@@ -50,8 +52,6 @@ export const getErrorMessage = err => {
50
52
  if (status === 500 || status === 502) {
51
53
  return intl.get('Internal_server_error');
52
54
  }
53
- // log error to locate problems
54
- console.error(err);
55
55
  return intl.get('Error');
56
56
  };
57
57
  export const getGeoGranularityByLevel = mapLevel => {
@@ -3,6 +3,7 @@ import _RateFormatter from "dtable-ui-component/lib/RateFormatter";
3
3
  import React from 'react';
4
4
  import { CellType, FORMULA_RESULT_TYPE, getNumberDisplayString, getDateDisplayString, getCellValueStringResult, isNumber, isDateColumn, isValidLink } from 'dtable-utils';
5
5
  import dayjs from 'dayjs';
6
+ import { isEqual } from 'lodash-es';
6
7
  import cellFormatterFactory from '../components/cell-factory/cell-formatter-factory';
7
8
  import SimpleCellFormatter from '../components/cell-factory/SimpleCellFormatter';
8
9
  import SingleSelectOption from '../components/cell-factory/SingleSelectOption';
@@ -517,7 +518,8 @@ export const getFilterConditions = function (statisticRecord, chart) {
517
518
  let columns = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
518
519
  const {
519
520
  name = '',
520
- group_name = ''
521
+ group_name = '',
522
+ rows
521
523
  } = statisticRecord || {};
522
524
  const {
523
525
  config
@@ -528,11 +530,34 @@ export const getFilterConditions = function (statisticRecord, chart) {
528
530
  const filters = [];
529
531
  const columnKey = xAxisMap[type];
530
532
  const groupColumnKey = groupAxisMap[type];
531
- const columnFilter = getFilterByColumnType(config[columnKey], columns, name);
532
- filters.push(columnFilter);
533
- if (config[groupColumnKey]) {
534
- const groupColumnFilter = getFilterByColumnType(config[groupColumnKey], columns, group_name);
535
- filters.push(groupColumnFilter);
533
+ if (!group_name && (rows === null || rows === void 0 ? void 0 : rows.length)) {
534
+ const xValueList = [];
535
+ const yValueList = [];
536
+ rows.forEach(r => {
537
+ const xValue = r[config[columnKey]];
538
+ const yValue = r[config[groupColumnKey]];
539
+ if (!xValueList.some(v => isEqual(v, xValue))) {
540
+ xValueList.push(xValue);
541
+ }
542
+ if (!yValueList.some(v => isEqual(v, yValue))) {
543
+ yValueList.push(yValue);
544
+ }
545
+ });
546
+ if (xValueList.length === 1) {
547
+ const columnFilter = getFilterByColumnType(config[columnKey], columns, xValueList[0]);
548
+ filters.push(columnFilter);
549
+ }
550
+ if (yValueList.length === 1) {
551
+ const columnFilter = getFilterByColumnType(config[groupColumnKey], columns, yValueList[0]);
552
+ filters.push(columnFilter);
553
+ }
554
+ } else {
555
+ const columnFilter = getFilterByColumnType(config[columnKey], columns, name);
556
+ filters.push(columnFilter);
557
+ if (config[groupColumnKey]) {
558
+ const groupColumnFilter = getFilterByColumnType(config[groupColumnKey], columns, group_name);
559
+ filters.push(groupColumnFilter);
560
+ }
536
561
  }
537
562
  return filters;
538
563
  };
@@ -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
  };
@@ -134,7 +133,7 @@ class TwoDimensionTable extends PureComponent {
134
133
  if (summaryColumns && (summaryColumns === null || summaryColumns === void 0 ? void 0 : summaryColumns.length) !== 0) {
135
134
  return summaryColumns.map(item => {
136
135
  return /*#__PURE__*/React.createElement("div", {
137
- key: "table-cell-".concat(item.key),
136
+ key: "table-cell-".concat(item === null || item === void 0 ? void 0 : item.key),
138
137
  className: classnames('pivot-cell', {
139
138
  'pivot-empty-cell': true
140
139
  })
@@ -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.88",
3
+ "version": "0.0.89beta",
4
4
  "main": "./dist/index.js",
5
5
  "dependencies": {
6
6
  "@antv/data-set": "0.11.8",
@@ -29,13 +29,13 @@
29
29
  "react-dom": "^17.0.0"
30
30
  },
31
31
  "scripts": {
32
- "clean": "rm -rf dist && mkdir dist",
32
+ "clean": "rimraf dist && mkdirp dist",
33
33
  "start.bak": "node scripts/start.js",
34
34
  "build": "node scripts/build.js",
35
35
  "pub:dist": "cross-env BABEL_ENV=production ./node_modules/.bin/babel src --out-dir dist --copy-files",
36
36
  "eslint": "eslint --ext .jsx,.js src --max-warnings=0",
37
37
  "lint": "lint-staged",
38
- "pub:optimized": "rm dist/config.js",
38
+ "pub:optimized": "rimraf dist/config.js",
39
39
  "prepare": "husky install",
40
40
  "prepublishOnly": "npm run clean && npm run pub:dist",
41
41
  "release": "release-it",
@@ -122,6 +122,7 @@
122
122
  "koa2-cors": "2.0.6",
123
123
  "lint-staged": "14.0.0",
124
124
  "mini-css-extract-plugin": "^1.3.5",
125
+ "mkdirp": "^3.0.1",
125
126
  "nodemon": "^3.1.0",
126
127
  "object-assign": "4.1.1",
127
128
  "pnp-webpack-plugin": "1.5.0",
@@ -144,6 +145,7 @@
144
145
  "release-it": "16.2.1",
145
146
  "resolve": "1.12.0",
146
147
  "resolve-url-loader": "5.0.0",
148
+ "rimraf": "^5.0.7",
147
149
  "sass-loader": "13.3.2",
148
150
  "style-loader": "^1.0.1",
149
151
  "terser-webpack-plugin": "4.2.3",