sea-chart 0.0.91 → 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.
@@ -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,7 +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
+ group_color: result.color || CHART_STYLE_COLORS[0],
179
179
  name: getFormattedLabel(groupbyColumn, result.name, value.collaborators)
180
180
  };
181
181
  });
@@ -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,
@@ -324,12 +324,12 @@ async function calculateTwoDimensionTable(chart, value, _ref2) {
324
324
  // format shown label(name)
325
325
  const map = {};
326
326
  pivot_columns.forEach(column => {
327
- const name = getFormattedLabel(rowGroupbyColumn, column.key, value.collaborators);
327
+ const name = getFormattedLabel(rowGroupbyColumn, column.key, value.collaborators, chart.type);
328
328
  map[column.key] = name;
329
329
  column.key = name;
330
330
  });
331
331
  pivot_rows.forEach(row => {
332
- row.name = getFormattedLabel(groupbyColumn, row.name, value.collaborators);
332
+ row.name = getFormattedLabel(groupbyColumn, row.name, value.collaborators, chart.type);
333
333
  const cells = {};
334
334
  Object.keys(row.cells).forEach(key => {
335
335
  cells[map[key]] = row.cells[key];
@@ -29,9 +29,7 @@ export const isValidRow = (row, formulaRow, column, includeEmpty) => {
29
29
  }
30
30
  return cellValue || cellValue === 0;
31
31
  };
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];
32
+ const RETURN_ARRAY_CHART_TYPES = [CHART_TYPE.TABLE];
35
33
  export const getFormattedLabel = (column, name, collaborators, chartType) => {
36
34
  let {
37
35
  type: columnType,
@@ -53,22 +51,22 @@ export const getFormattedLabel = (column, name, collaborators, chartType) => {
53
51
  return optionName;
54
52
  }
55
53
  } 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
- }
67
54
  // Return the array directly and process it in the rendering, file directly: src/view/wrapper/table/pivot-table-display-name.js
68
- if (Array.isArray(name)) {
69
- return name;
55
+ if (RETURN_ARRAY_CHART_TYPES.includes(chartType)) {
56
+ if (Array.isArray(name)) {
57
+ return name;
58
+ }
59
+ return [];
70
60
  }
71
- 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;
72
70
  } else if (columnType === CellType.COLLABORATOR) {
73
71
  let collaborator = collaborators.find(item => {
74
72
  let email = name;
@@ -85,8 +85,8 @@ class BarGroup extends ChartComponent {
85
85
  const theme = CHART_THEME_COLOR[globalTheme];
86
86
  const isGroup = type === CHART_TYPE.BAR_GROUP;
87
87
  const newData = this.getChartGroupData(data);
88
- const groupByColumn = this.getColumn(tables, table_id, column_groupby_column_key);
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;
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;
90
90
  let singleBarWidth, singleBarRadius;
91
91
  // y-axis label width:6 + 10
92
92
  const chartWidth = this.chart.width - 6 - 10;
@@ -146,7 +146,9 @@ class BarGroup extends ChartComponent {
146
146
  type: 'dodge',
147
147
  marginRatio: 0
148
148
  };
149
- this.setColorMap(data, chartColorTheme);
149
+
150
+ // use single select column color
151
+ useSingleSelectColumnColor ? this.setSingleSelectColorMap(data) : this.setColorMap(data, chartColorTheme);
150
152
  this.chart.interval().animate({
151
153
  // custom update animation
152
154
  update: {
@@ -162,8 +164,8 @@ class BarGroup extends ChartComponent {
162
164
  lineWidth: 1
163
165
  },
164
166
  position: type === CHART_TYPE.BAR_STACK ? 'middle' : ''
165
- }).position('name*value').size(singleBarWidth).color('group_name*group_color', (group_name, group_color) => {
166
- 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];
167
169
  }).tooltip('name*value*group_name*raw_name', (name, value, group_name, raw_name) => {
168
170
  return {
169
171
  title: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name,
@@ -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 => {
@@ -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({
@@ -99,6 +99,7 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
99
99
  total
100
100
  }, selectedCell);
101
101
  };
102
+ // click records only support summary_type is COUNT
102
103
  this.renderRows = () => {
103
104
  const {
104
105
  result,
@@ -177,15 +178,9 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
177
178
  'selected-pivot-cell-top': isSelectedCellTop,
178
179
  'selected-pivot-cell-left': isSelectedCellLeft
179
180
  }),
180
- key: "table-cell-".concat(cellIdx),
181
- onClick: () => this.toggleRecords({
182
- rows,
183
- name: rowItem === null || rowItem === void 0 ? void 0 : rowItem.name,
184
- total: total[key]
185
- }, {
186
- rowIdx,
187
- cellIdx
188
- }),
181
+ key: "table-cell-".concat(cellIdx)
182
+ // onClick={() => this.toggleRecords({ rows, name: rowItem?.name, total: total[key] }, { rowIdx, cellIdx })}
183
+ ,
189
184
  title: isValidDisplayValue ? displayValue : ''
190
185
  }, isValidDisplayValue ? displayValue : /*#__PURE__*/React.createElement("i", null), /*#__PURE__*/React.createElement("span", {
191
186
  className: classnames({
@@ -197,14 +192,9 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
197
192
  'selected-pivot-cell': isSelectedTotalCell,
198
193
  'selected-pivot-cell-top': isSelectedTotalCellTop,
199
194
  '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
- }),
195
+ })
196
+ // onClick={() => this.toggleRecords({ rows, name: rowItem?.name, total: rowTotal }, { rowIdx })}
197
+ ,
208
198
  title: rowTotal ? rowTotal : 0
209
199
  }, rowTotal ? rowTotal : /*#__PURE__*/React.createElement("i", null, "0"), /*#__PURE__*/React.createElement("span", {
210
200
  className: classnames({
@@ -230,14 +220,9 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
230
220
  'selected-pivot-cell': isSelectRowTotalCell,
231
221
  'selected-pivot-cell-left': isSelectRowTotalCellLeft
232
222
  }),
233
- key: "total-cell-".concat(index),
234
- onClick: () => this.toggleRecords({
235
- rows: pivotColumnCell,
236
- total: pivot_columns_total[c.key]
237
- }, {
238
- rowIdx: pivot_rows.length,
239
- cellIdx: index
240
- }),
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
+ ,
241
226
  title: totalDisplayValue
242
227
  }, isValidTotalDisplayValue ? totalDisplayValue : /*#__PURE__*/React.createElement("i", null), /*#__PURE__*/React.createElement("span", {
243
228
  className: classnames({
@@ -247,14 +232,9 @@ class OneDimensionTableWithNumericColumns extends PureComponent {
247
232
  }), /*#__PURE__*/React.createElement("td", {
248
233
  className: classnames('pivot-cell', {
249
234
  '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
- }),
235
+ })
236
+ // onClick={() => this.toggleRecords({ rows: lastRows, total: lastRowTotal }, { rowIdx: pivot_rows.length, cellIdx: pivot_columns?.length })}
237
+ ,
258
238
  title: lastRowTotal
259
239
  }, BaseUtils.isValidValue(lastRowTotal, display_empty) ? lastRowTotal : /*#__PURE__*/React.createElement("i", null))));
260
240
  };
@@ -108,7 +108,7 @@ class TwoDimensionTable extends PureComponent {
108
108
  })));
109
109
  };
110
110
  this.toggleRecords = (cell, selectedCell) => {
111
- if (window.isMobile) return;
111
+ if (window.isMobile || !this.isCount) return;
112
112
  const {
113
113
  rowIdx: selectedRowIdx,
114
114
  cellIdx: selectedCellIdx
@@ -121,7 +121,7 @@ class TwoDimensionTable extends PureComponent {
121
121
  this.props.toggleRecords(cell, selectedCell);
122
122
  };
123
123
  this.onClickTotals = (recordsList, selectedCell) => {
124
- if (window.isMobile) return;
124
+ if (window.isMobile || !this.isCount) return;
125
125
  const rows = recordsList.flat();
126
126
  const total = rows.length;
127
127
  this.toggleRecords({
@@ -186,6 +186,7 @@ class TwoDimensionTable extends PureComponent {
186
186
  const tableTotalDisplayValue = BaseUtils.getSummaryValueDisplayString(summaryColumn, pivot_table_total, summaryMethod);
187
187
  const isValidTableTotalDisplayValue = BaseUtils.isValidValue(tableTotalDisplayValue, display_empty);
188
188
  const isCount = summary_type === CHART_SUMMARY_TYPE.COUNT;
189
+ this.isCount = isCount;
189
190
  const isCollaborator = groupbyColumn.type === CellType.COLLABORATOR;
190
191
  return /*#__PURE__*/React.createElement("tbody", null, pivotRowsLen > 0 && pivot_rows.map((rowItem, rowIdx) => {
191
192
  let {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sea-chart",
3
- "version": "0.0.91",
3
+ "version": "0.0.92",
4
4
  "main": "./dist/index.js",
5
5
  "dependencies": {
6
6
  "@antv/data-set": "0.11.8",