sea-chart 0.0.95 → 0.0.97

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.
@@ -16,7 +16,7 @@ export const ONLY_NEED_NUMBER_OPTIONS_CHART_TYPE = [CHART_TYPE.COMPLETENESS, CHA
16
16
  export const COMPLETENESS_GROUPBY_SUPPORTED_COLUMN_TYPE = [CellType.COLLABORATOR, CellType.TEXT, CellType.SINGLE_SELECT];
17
17
  export const NUMBERIC_COLUMN_TYPE = [CellType.RATE, CellType.NUMBER];
18
18
  export const ZH_CN_SUPPORT_CHARTS = [CHART_TYPE.MAP, CHART_TYPE.MAP_BUBBLE];
19
- export const SUPPORT_DATA_SORT_CHART_TYPES = [CHART_TYPE.BAR, CHART_TYPE.BAR_STACK, CHART_TYPE.LINE, CHART_TYPE.PIE, CHART_TYPE.RING, CHART_TYPE.HORIZONTAL_BAR, CHART_TYPE.AREA, CHART_TYPE.TREE_MAP];
19
+ export const SUPPORT_DATA_SORT_CHART_TYPES = [CHART_TYPE.BAR, CHART_TYPE.BAR_STACK, CHART_TYPE.LINE, CHART_TYPE.PIE, CHART_TYPE.RING, CHART_TYPE.HORIZONTAL_BAR, CHART_TYPE.STACKED_HORIZONTAL_BAR, CHART_TYPE.AREA, CHART_TYPE.TREE_MAP];
20
20
  export const SUPPORT_STACK_VALUE_CHART_TYPES = [CHART_TYPE.BAR_STACK, CHART_TYPE.BAR_CUSTOM];
21
21
  export const X_AXIS_IS_GROUPBY_COLUMN_KEY_CHART_TYPES = [CHART_TYPE.TABLE, CHART_TYPE.PIE, CHART_TYPE.RING, CHART_TYPE.TREE_MAP];
22
22
  export const CHART_CHART_MAP = {
@@ -6,8 +6,9 @@ import Divider from '../widgets/divider';
6
6
  import GroupBy from '../widgets/group-by';
7
7
  import YAxisGroupSettings from '../widgets/y-axis-group-settings';
8
8
  import { islinkDateFormula } from '../../utils/column-utils';
9
- import { CHART_SUMMARY_TYPE, GEOLOCATION_FORMAT_CITY, GEOLOCATION_FORMAT_MAP } from '../../constants';
9
+ import { CHART_SUMMARY_TYPE, GEOLOCATION_FORMAT_CITY, GEOLOCATION_FORMAT_MAP, SUPPORT_DATA_SORT_CHART_TYPES } from '../../constants';
10
10
  import intl from '../../intl';
11
+ import DataSort from '../widgets/data-sort';
11
12
  const DataSettings = _ref => {
12
13
  let {
13
14
  chart,
@@ -95,6 +96,18 @@ const DataSettings = _ref => {
95
96
  x_axis_include_empty_cells: !x_axis_include_empty_cells
96
97
  });
97
98
  }, [chart, onChange]);
99
+ const renderDataSort = useCallback(() => {
100
+ const {
101
+ config
102
+ } = chart;
103
+ if (!SUPPORT_DATA_SORT_CHART_TYPES.includes(config.type)) return null;
104
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Divider, {
105
+ className: "mt-4"
106
+ }), /*#__PURE__*/React.createElement(DataSort, {
107
+ chart: chart,
108
+ onChange: onChange
109
+ }));
110
+ }, [chart, onChange]);
98
111
  const {
99
112
  config
100
113
  } = chart;
@@ -133,7 +146,7 @@ const DataSettings = _ref => {
133
146
  chart: chart,
134
147
  tables: tables,
135
148
  onChange: onChange
136
- }));
149
+ }), renderDataSort());
137
150
  };
138
151
  DataSettings.defaultProps = {
139
152
  xLabel: 'X_axis',
@@ -696,16 +696,14 @@ BaseUtils.sortCharts = (charts, column, sortKey) => {
696
696
  // key was used to sort "pivot columns" in pivot chart
697
697
  const {
698
698
  name: currentName,
699
- group_name: currentGroupName,
700
699
  key: currentKey
701
700
  } = currResult || {};
702
701
  const {
703
702
  name: nextName,
704
- group_name: nextGroupName,
705
703
  key: nextKey
706
704
  } = nextResult || {};
707
- const current = currentGroupName || currentName || currentKey;
708
- const next = nextGroupName || nextName || nextKey;
705
+ const current = currentName || currentKey;
706
+ const next = nextName || nextKey;
709
707
  return sortSingleSelect(current, next, {
710
708
  sort_type: sortType,
711
709
  option_id_index_map: optionIdIndexMap
@@ -763,12 +763,12 @@ SQLStatisticsUtils.basicChartSQLResult2JavaScript = (chart, sqlRows, chartSQLMap
763
763
  }
764
764
  }
765
765
  });
766
+ BaseUtils.sortCharts(result, groupbyColumn, 'name');
766
767
  BaseUtils.updateTableViewList(result, groupbyColumn, 'name', 'color');
767
768
  if (SUPPORT_DATA_SORT_CHART_TYPES.includes(type) && sort_type) {
768
769
  BaseUtils.sortChartData(result, sort_type);
769
770
  return result;
770
771
  }
771
- BaseUtils.sortCharts(result, groupbyColumn, 'name');
772
772
  return result;
773
773
  };
774
774
  SQLStatisticsUtils.basicNumberCardSQLResult2JavaScript = (chart, sqlRows, chartSQLMap, columnMap, tables) => {
@@ -876,8 +876,8 @@ SQLStatisticsUtils.customChartSQLResult2JavaScript = (chart, sqlRows, chartSQLMa
876
876
  });
877
877
  result = assembled;
878
878
  }
879
- BaseUtils.updateTableViewList(result, groupbyColumn, 'name', '');
880
879
  BaseUtils.sortCharts(result, groupbyColumn, 'name');
880
+ BaseUtils.updateTableViewList(result, groupbyColumn, 'name', '');
881
881
  return result;
882
882
  };
883
883
  SQLStatisticsUtils.compareSQLResult2Javascript = (chart, sqlRows, chartSQLMap, columnMap, tables) => {
@@ -1234,12 +1234,13 @@ SQLStatisticsUtils.updateGroupingChartRow = (results, name, groupName, row, coun
1234
1234
  updatedResult.value = updatedResult.value + count;
1235
1235
  results[updatedIndex] = updatedResult;
1236
1236
  } else {
1237
- results.push({
1237
+ const obj = {
1238
1238
  name,
1239
1239
  rows: [row],
1240
1240
  group_name: groupName,
1241
1241
  value: count
1242
- });
1242
+ };
1243
+ results.push(obj);
1243
1244
  }
1244
1245
  };
1245
1246
  SQLStatisticsUtils.updateGroupingChartRows = (results, name, row, count, isColumnGroupbyColumnDataAsAnArray, groupName) => {
@@ -1291,9 +1292,9 @@ SQLStatisticsUtils.groupingTwoDimensionChartSQLResult2JavaScript = (chart, sqlRo
1291
1292
  }
1292
1293
  }
1293
1294
  });
1295
+ BaseUtils.sortCharts(result, groupbyColumn, 'name');
1294
1296
  BaseUtils.updateTableViewList(result, groupbyColumn, 'name', 'color');
1295
1297
  BaseUtils.updateTableViewList(result, columnGroupbyColumn, 'group_name', 'group_color');
1296
- BaseUtils.sortCharts(result, groupbyColumn, 'name');
1297
1298
  return result;
1298
1299
  };
1299
1300
  SQLStatisticsUtils.groupingChartSQLResult2JavaScript = (chart, sqlRows, chartSQLMap, columnMap, tables) => {
@@ -1347,8 +1348,8 @@ SQLStatisticsUtils.groupingChartSQLResult2JavaScript = (chart, sqlRows, chartSQL
1347
1348
  });
1348
1349
  }
1349
1350
  });
1350
- BaseUtils.updateTableViewList(result, groupbyColumn, 'name', 'color');
1351
1351
  BaseUtils.sortCharts(result, groupbyColumn, 'name');
1352
+ BaseUtils.updateTableViewList(result, groupbyColumn, 'name', 'color');
1352
1353
  return result;
1353
1354
  }
1354
1355
  if (!columnGroupbyColumn) {
@@ -507,7 +507,7 @@ const getFilterByColumnType = (columnKey, columns, value) => {
507
507
  column_key: columnKey || ''
508
508
  };
509
509
  const column = getColumnByKey(columnKey, columns);
510
- if (isDateColumn(column) || (column === null || column === void 0 ? void 0 : column.type) === CellType.GEOLOCATION) {
510
+ if (column && (isDateColumn(column) || (column === null || column === void 0 ? void 0 : column.type) === CellType.GEOLOCATION)) {
511
511
  filter['value'] = value;
512
512
  return filter;
513
513
  }
@@ -569,7 +569,7 @@ export const getFilterConditions = function (statisticRecord, chart) {
569
569
  } else {
570
570
  const columnFilter = getFilterByColumnType(config[columnKey], columns, name);
571
571
  filters.push(columnFilter);
572
- if (config[groupColumnKey]) {
572
+ if (groupColumnKey && config[groupColumnKey]) {
573
573
  const groupColumnFilter = getFilterByColumnType(config[groupColumnKey], columns, group_name || groupby);
574
574
  filters.push(groupColumnFilter);
575
575
  }
@@ -1,12 +1,13 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { debounce, maxBy, throttle } from 'lodash-es';
3
+ import { debounce, maxBy } from 'lodash-es';
4
4
  import classNames from 'classnames';
5
5
  import { CellType } from 'dtable-ui-component/lib/constants';
6
6
  import { CHART_TYPE, EMPTY_NAME, CHART_THEME_COLOR, CHART_STYLE_COLORS } from '../../constants';
7
7
  import { BaseUtils, isFunction } from '../../utils';
8
8
  import intl from '../../intl';
9
9
  import { STACK_AND_PIE_CHART_THEMES_OPTIONS } from '../../constants/color-rules';
10
+ import { sortDataByGroupSum } from '../../utils/column-utils';
10
11
  import HorizontalComponent from './horizontal-component';
11
12
  class HorizontalBarGroup extends HorizontalComponent {
12
13
  constructor(props) {
@@ -40,13 +41,21 @@ class HorizontalBarGroup extends HorizontalComponent {
40
41
  this.drawChart = () => {
41
42
  let {
42
43
  result: data,
43
- customRender
44
+ customRender,
45
+ chart
44
46
  } = this.props;
45
47
  data = BaseUtils.formatEmptyName(data, '', intl.get('Empty'));
46
48
  if (!Array.isArray(data)) return;
47
49
  this.chart.scale(this.groupName, {
48
50
  type: 'cat'
49
51
  });
52
+ const {
53
+ sort_type,
54
+ type
55
+ } = chart.config;
56
+ if (type === CHART_TYPE.STACKED_HORIZONTAL_BAR && sort_type) {
57
+ data = sortDataByGroupSum(data, sort_type);
58
+ }
50
59
  this.loadData(data);
51
60
  this.draw(data);
52
61
  isFunction(customRender) && customRender(this.chart);
@@ -1,7 +1,7 @@
1
1
  import React, { Fragment } from 'react';
2
2
  import shallowEqual from 'shallowequal';
3
3
  import dayjs from 'dayjs';
4
- import { CellType, COLLABORATOR_COLUMN_TYPES, FORMULA_RESULT_TYPE, getOption, getCollaborator, getNumberDisplayString, isNumber } from 'dtable-utils';
4
+ import { CellType, COLLABORATOR_COLUMN_TYPES, FORMULA_RESULT_TYPE, getOption, getCollaborator, getNumberDisplayString, isNumber, isValidEmail } from 'dtable-utils';
5
5
  import { getClientFormulaDisplayString, getKnownCollaboratorByEmail, getColumnOptions, getDateColumnFormat, generateDefaultUser } from '../../../utils';
6
6
  import { Collaborator } from '../../../components';
7
7
  import intl from '../../../intl';
@@ -10,7 +10,21 @@ import { CHART_THEME_COLOR } from '../../../constants';
10
10
  class PivotTableDisplayName extends React.Component {
11
11
  constructor(props) {
12
12
  super(props);
13
- this.updateCreator = email => {
13
+ this.getType = column => {
14
+ let type = column.type;
15
+ if (type === CellType.LINK_FORMULA) {
16
+ var _column$data;
17
+ type = column === null || column === void 0 ? void 0 : (_column$data = column.data) === null || _column$data === void 0 ? void 0 : _column$data.array_type;
18
+ }
19
+ return type;
20
+ };
21
+ this.updateCreator = (email, rowData) => {
22
+ if (!isValidEmail(email)) {
23
+ const {
24
+ original_name
25
+ } = rowData;
26
+ email = original_name;
27
+ }
14
28
  let creator = getKnownCollaboratorByEmail(email);
15
29
  if (creator) {
16
30
  this.setState({
@@ -100,14 +114,10 @@ class PivotTableDisplayName extends React.Component {
100
114
  type,
101
115
  data
102
116
  } = column;
117
+ type = this.getType(column);
103
118
  const {
104
119
  collaborators
105
120
  } = 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
- }
111
121
  let displayName;
112
122
  switch (type) {
113
123
  case CellType.SINGLE_SELECT:
@@ -295,22 +305,23 @@ class PivotTableDisplayName extends React.Component {
295
305
  componentDidMount() {
296
306
  let {
297
307
  column,
298
- value
308
+ value,
309
+ rowData
299
310
  } = this.props;
300
- if (column.type !== CellType.CREATOR && column.type !== CellType.LAST_MODIFIER) return;
301
- this.updateCreator(value);
311
+ const type = this.getType(column);
312
+ if (type !== CellType.CREATOR && type !== CellType.LAST_MODIFIER) return;
313
+ this.updateCreator(value, rowData);
302
314
  }
303
315
  UNSAFE_componentWillReceiveProps(nextProps) {
304
316
  let {
305
317
  column,
306
- value
318
+ value,
319
+ rowData
307
320
  } = nextProps;
308
- let {
309
- type
310
- } = column;
321
+ const type = this.getType(column);
311
322
  if (type !== CellType.CREATOR && type !== CellType.LAST_MODIFIER) return;
312
323
  if (value !== this.props.value || shallowEqual(nextProps.column, this.props.column)) {
313
- this.updateCreator(value);
324
+ this.updateCreator(value, rowData);
314
325
  }
315
326
  }
316
327
  render() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sea-chart",
3
- "version": "0.0.95",
3
+ "version": "0.0.97",
4
4
  "main": "./dist/index.js",
5
5
  "dependencies": {
6
6
  "@antv/data-set": "0.11.8",