sea-chart 0.0.51 → 0.0.53-alpha.0

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.
@@ -10,27 +10,7 @@ import ObjectUtils from '../object-utils';
10
10
  import intl from '../../intl';
11
11
  import context from '../../context';
12
12
  import { isValidCollaboratorEmail } from '../collaborator';
13
- class BaseUtils {
14
- constructor() {
15
- this.sortDataByKey = (data, key, sortType) => {
16
- data.sort((curr, next) => {
17
- const currentVal = curr[key];
18
- const nextVal = next[key];
19
- if (!currentVal && currentVal !== 0) {
20
- return -1;
21
- }
22
- if (!nextVal && nextVal !== 0) {
23
- return 1;
24
- }
25
- if (sortType === CHART_DATA_SORT_TYPE.ASCENDING) {
26
- return currentVal > nextVal ? 1 : -1;
27
- } else {
28
- return currentVal > nextVal ? -1 : 1;
29
- }
30
- });
31
- };
32
- }
33
- }
13
+ class BaseUtils {}
34
14
  _BaseUtils = BaseUtils;
35
15
  BaseUtils.isCollaborator = column => {
36
16
  return column.type === CellType.COLLABORATOR;
@@ -267,7 +247,7 @@ BaseUtils.getSummaryValueDisplayString = function (summaryColumn, summaryValue)
267
247
  let summaryMethod = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'count';
268
248
  if (!summaryColumn) return summaryValue;
269
249
  if (!summaryValue && summaryValue !== 0) return summaryValue;
270
- if (summaryMethod.toUpperCase() === 'DISTINCT_VALUES') return summaryValue;
250
+ if ((summaryMethod === null || summaryMethod === void 0 ? void 0 : summaryMethod.toUpperCase()) === 'DISTINCT_VALUES') return summaryValue;
271
251
  const {
272
252
  data
273
253
  } = summaryColumn;
@@ -768,6 +748,23 @@ BaseUtils.sortByDate = (currentDate, nextDate) => {
768
748
  if (currentDate.name < nextDate.name) return -1;
769
749
  return 0;
770
750
  };
751
+ BaseUtils.sortDataByKey = (data, key, sortType) => {
752
+ data.sort((curr, next) => {
753
+ const currentVal = curr[key];
754
+ const nextVal = next[key];
755
+ if (!currentVal && currentVal !== 0) {
756
+ return -1;
757
+ }
758
+ if (!nextVal && nextVal !== 0) {
759
+ return 1;
760
+ }
761
+ if (sortType === CHART_DATA_SORT_TYPE.ASCENDING) {
762
+ return currentVal > nextVal ? 1 : -1;
763
+ } else {
764
+ return currentVal > nextVal ? -1 : 1;
765
+ }
766
+ });
767
+ };
771
768
  BaseUtils.moveNullDataToEnd = arr => {
772
769
  let nullData;
773
770
  const nullDataIndex = arr.findIndex(item => {
@@ -1348,4 +1345,34 @@ BaseUtils.summaryDurationResult = (result, duration, summaryType, summaryMethod,
1348
1345
  comparedValue
1349
1346
  };
1350
1347
  };
1348
+ BaseUtils.mergePivotTableSameCollaborator = pivot_rows => {
1349
+ const new_pivot_rows = [];
1350
+ pivot_rows.forEach(item => {
1351
+ var _item$name;
1352
+ if ((item === null || item === void 0 ? void 0 : (_item$name = item.name) === null || _item$name === void 0 ? void 0 : _item$name.length) === 1) {
1353
+ const curCollaborator = item.name[0];
1354
+ const length = new_pivot_rows.length;
1355
+ if (length >= 1 && new_pivot_rows[length - 1]) {
1356
+ var _new_pivot_rows;
1357
+ const preCollaborator = (_new_pivot_rows = new_pivot_rows[length - 1]) === null || _new_pivot_rows === void 0 ? void 0 : _new_pivot_rows.name[0];
1358
+ if (curCollaborator === preCollaborator) {
1359
+ const newItem = {
1360
+ ...item,
1361
+ cells: {
1362
+ ...new_pivot_rows[length - 1].cells,
1363
+ ...item.cells
1364
+ },
1365
+ total: new_pivot_rows[length - 1].total + item.total
1366
+ };
1367
+ new_pivot_rows[length - 1] = newItem;
1368
+ return;
1369
+ }
1370
+ }
1371
+ new_pivot_rows.push({
1372
+ ...item
1373
+ });
1374
+ }
1375
+ });
1376
+ return new_pivot_rows;
1377
+ };
1351
1378
  export default BaseUtils;
@@ -646,6 +646,7 @@ SQLStatisticsUtils.twoDimensionTableSQLResult2JavaScript = (chart, sqlRows, char
646
646
  pivot_table_total, chart);
647
647
  BaseUtils.sortCharts(pivot_rows, groupbyColumn, 'name');
648
648
  BaseUtils.sortCharts(pivot_columns, columnGroupbyColumn, 'key');
649
+ pivot_rows = BaseUtils.mergePivotTableSameCollaborator(pivot_rows);
649
650
  const summary_columns = [summaryColumn, ...summaryColumnsWithMethod.map(item => item.column)];
650
651
  return {
651
652
  summary_columns,
@@ -3,7 +3,7 @@ import { COLUMNS_ICON_CONFIG } from 'dtable-utils';
3
3
  import React from 'react';
4
4
  import { MIRROR_COLUMN_LIST, CHART_SUMMARY_TYPE } from '../constants';
5
5
  import { getClientFormulaDisplayString } from './cell-format-utils';
6
- import { ChartUtils } from './chart-utils';
6
+ import { BaseUtils } from './chart-utils';
7
7
 
8
8
  // get dtable column options
9
9
  export function getColumnOptions(columns) {
@@ -461,7 +461,7 @@ export const sortDataByGroupSum = (data, sortType) => {
461
461
  });
462
462
 
463
463
  // sort group
464
- ChartUtils.sortDataByKey(nameSumMap, 'valueSum', sortType);
464
+ BaseUtils.sortDataByKey(nameSumMap, 'valueSum', sortType);
465
465
  return nameSumMap.reduce((accumulator, currentItem) => accumulator.concat(currentItem.items), []);
466
466
  };
467
467
  export const formatNumericValue = function (value) {
@@ -58,8 +58,6 @@
58
58
 
59
59
  .sea-chart-formatter .sea-chart-trend-formatter-container {
60
60
  padding: 20px;
61
- border: 2px solid #e2e2e2;
62
- border-radius: 6px;
63
61
  }
64
62
 
65
63
  .sea-chart-formatter .sea-chart-container.show-x-axis-label,
@@ -25,12 +25,15 @@ class Table extends PureComponent {
25
25
  return /*#__PURE__*/React.createElement("div", null, intl.get('There_are_too_many_statistics_entries_to_display'));
26
26
  }
27
27
  if (columnGroupbyColumn) {
28
+ console.log('TwoDimensionTable');
28
29
  return /*#__PURE__*/React.createElement(TwoDimensionTable, this.props);
29
30
  }
30
31
  if (!Array.isArray(pivot_columns)) return null;
31
32
  if (pivot_columns.length < 2) {
33
+ console.log('NoNumericColumns');
32
34
  return /*#__PURE__*/React.createElement(OneDimensionTableNoNumericColumns, this.props);
33
35
  }
36
+ console.log('WithNumericColumns');
34
37
  return /*#__PURE__*/React.createElement(OneDimensionTableWithNumericColumns, this.props);
35
38
  };
36
39
  }
@@ -38,6 +41,7 @@ class Table extends PureComponent {
38
41
  const {
39
42
  result
40
43
  } = this.props;
44
+ console.log('result', result);
41
45
  return /*#__PURE__*/React.createElement("div", {
42
46
  className: "sea-chart-table-wrapper sea-chart-".concat(result.dimensions, "-table-wrapper")
43
47
  // onClick={this.onTableClick}
@@ -105,7 +105,8 @@ class OneDimensionTableNoNumericColumns extends PureComponent {
105
105
  })
106
106
  }, /*#__PURE__*/React.createElement(PivotTableDisplayName, {
107
107
  value: name,
108
- column: groupbyColumn
108
+ column: groupbyColumn,
109
+ rowData: rowItem
109
110
  })), display_total && /*#__PURE__*/React.createElement("td", {
110
111
  className: classnames('pivot-cell', {
111
112
  'pivot-empty-cell': !isValidTotalDisplayValue,
@@ -124,7 +124,8 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
124
124
  })
125
125
  }, /*#__PURE__*/React.createElement(PivotTableDisplayName, {
126
126
  value: name,
127
- column: groupbyColumn
127
+ column: groupbyColumn,
128
+ rowData: rowItem
128
129
  })), Array.isArray(pivot_columns) && pivot_columns.map((columnMap, cellIdx) => {
129
130
  const isSelectedCell = selectRowIdx === rowIdx && selectedCellIdx === cellIdx;
130
131
  const isSelectedCellTop = selectRowIdx - 1 === rowIdx && selectedCellIdx === cellIdx;
@@ -73,6 +73,7 @@ class PivotTableDisplayName extends React.Component {
73
73
  }, optionName);
74
74
  };
75
75
  this.renderCollaborator = collaborator => {
76
+ console.log('renderCollaborator', collaborator);
76
77
  if (!collaborator) return null;
77
78
  const {
78
79
  avatar_url,
@@ -103,6 +104,7 @@ class PivotTableDisplayName extends React.Component {
103
104
  collaborators
104
105
  } = this.state;
105
106
  let displayName;
107
+ console.log('column-type', type, column);
106
108
  switch (type) {
107
109
  case CellType.SINGLE_SELECT:
108
110
  {
@@ -128,7 +130,16 @@ class PivotTableDisplayName extends React.Component {
128
130
  }
129
131
  case CellType.COLLABORATOR:
130
132
  {
131
- const validValue = Array.isArray(value) && value.length !== 0 ? value : [];
133
+ const {
134
+ rowData
135
+ } = this.props;
136
+ const {
137
+ original_name
138
+ } = rowData || {};
139
+ let validValue = Array.isArray(value) && value.length !== 0 ? value : [];
140
+ if (original_name) {
141
+ validValue = [original_name];
142
+ }
132
143
  const unknowEmails = validValue.filter(email => !getCollaborator(collaborators, email));
133
144
 
134
145
  // if need to query unknowEmails
@@ -229,6 +240,7 @@ class PivotTableDisplayName extends React.Component {
229
240
  let user = array_type === CellType.COLLABORATOR ? getCollaborator(collaborators, email) : getKnownCollaboratorByEmail(email);
230
241
  return (user || {}).name;
231
242
  });
243
+ displayValue = displayValue.join(' ');
232
244
  }
233
245
  }
234
246
  displayName = /*#__PURE__*/React.createElement("div", {
@@ -78,7 +78,8 @@ class TwoDimensionTable extends PureComponent {
78
78
  key: "pivot-column-".concat(index)
79
79
  }, /*#__PURE__*/React.createElement(PivotTableDisplayName, {
80
80
  value: original_key,
81
- column: columnGroupbyColumn || {}
81
+ column: columnGroupbyColumn || {},
82
+ rowData: item
82
83
  }));
83
84
  }), display_total && /*#__PURE__*/React.createElement("th", {
84
85
  className: classnames('pivot-table-header', {
@@ -186,7 +187,8 @@ class TwoDimensionTable extends PureComponent {
186
187
  })
187
188
  }, /*#__PURE__*/React.createElement(PivotTableDisplayName, {
188
189
  value: name,
189
- column: groupbyColumn
190
+ column: groupbyColumn,
191
+ rowData: rowItem
190
192
  })), Array.isArray(cells) && cells.map((c, cellIdx) => {
191
193
  const isSelectedCell = selectRowIdx === rowIdx && selectedCellIdx === cellIdx;
192
194
  const isSelectedCellTop = selectRowIdx - 1 === rowIdx && selectedCellIdx === cellIdx;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sea-chart",
3
- "version": "0.0.51",
3
+ "version": "0.0.53-alpha.0",
4
4
  "main": "./dist/index.js",
5
5
  "dependencies": {
6
6
  "@antv/data-set": "0.11.8",