sea-chart 0.0.10 → 0.0.12

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.
@@ -58,7 +58,7 @@ export const CHART_TYPE_SHOW = {
58
58
  [CHART_TYPE.TREND]: 'Trend',
59
59
  [CHART_TYPE.DASHBOARD]: 'Gauge',
60
60
  [CHART_TYPE.TREE_MAP]: 'Tree_map',
61
- [CHART_TYPE.TABLE]: 'Table'
61
+ [CHART_TYPE.TABLE]: 'Pivot_table'
62
62
  };
63
63
  export const CHART_TYPES = [{
64
64
  name: 'Histogram',
@@ -120,7 +120,7 @@ export const CHART_TYPES = [{
120
120
  icon: 'rectangular-tree-diagram',
121
121
  children: [CHART_TYPE.TREE_MAP]
122
122
  }, {
123
- name: 'Pivot_table',
123
+ name: 'Table',
124
124
  icon: 'dtable-logo',
125
125
  children: [CHART_TYPE.TABLE]
126
126
  }];
@@ -91,7 +91,6 @@ const en = {
91
91
  'Filters': 'filters',
92
92
  'Font_size': 'Font size',
93
93
  'Font_weight': 'Font weight',
94
- 'Table': 'Table',
95
94
  'Chart_type': 'Chart type',
96
95
  "Histogram": "Histogram",
97
96
  "Basic_histogram": "Basic histogram",
@@ -91,7 +91,6 @@ const zh_CN = {
91
91
  "Filters": "个过滤条件",
92
92
  "Font_size": "字体大小",
93
93
  "Font_weight": "字体粗细",
94
- 'Table': '子表',
95
94
  'Chart_type': '图表类型',
96
95
  "Histogram": "柱状图",
97
96
  "Basic_histogram": "基础柱状图",
@@ -126,7 +125,6 @@ const zh_CN = {
126
125
  "Trend": "趋势图",
127
126
  "Gauge": "仪表盘",
128
127
  "Tree_map": "矩形树图",
129
- "Pivot_table": "透视表 Pivot table",
130
128
  "Table": '表格',
131
129
  "Pivot_table": "透视表",
132
130
  "Title": "标题",
@@ -79,8 +79,9 @@ const Settings = _ref => {
79
79
  chart: chart,
80
80
  tables: tables,
81
81
  onChange: modifyStatistic
82
- }), type === CHART_SETTINGS_TYPE.STYLE && /*#__PURE__*/React.createElement(StyleSettings, {
82
+ }), type === CHART_SETTINGS_TYPE.CHART_STYLE && /*#__PURE__*/React.createElement(StyleSettings, {
83
83
  chart: chart,
84
+ labelColorConfigs: labelColorConfigs,
84
85
  onChange: modifyStyle
85
86
  }), children && type === CHART_SETTINGS_TYPE.GENERAL_STYLE && /*#__PURE__*/React.createElement(React.Fragment, null, children))));
86
87
  };
@@ -50,12 +50,13 @@ class ColorUseTypeSelector extends Component {
50
50
  case CHART_TYPE.STACKED_HORIZONTAL_BAR:
51
51
  case CHART_TYPE.PIE:
52
52
  case CHART_TYPE.RING:
53
- case CHART_TYPE.GROUP_LINE:
54
- case CHART_TYPE.AREA_GROUP_CHART:
53
+ case CHART_TYPE.LINE_GROUP:
54
+ case CHART_TYPE.AREA_GROUP:
55
55
  {
56
56
  return [TYPE_COLOR_USING.USE_DEFAULT, TYPE_COLOR_USING.USE_COLUMN_COLORS];
57
57
  }
58
58
  case CHART_TYPE.BAR:
59
+ case CHART_TYPE.LINE:
59
60
  case CHART_TYPE.HORIZONTAL_BAR:
60
61
  {
61
62
  return [TYPE_COLOR_USING.USE_DEFAULT, TYPE_COLOR_USING.USE_SPECIFIC_COLORS, TYPE_COLOR_USING.USE_RULES];
@@ -92,6 +93,7 @@ class ColorUseTypeSelector extends Component {
92
93
  type
93
94
  } = chart;
94
95
  switch (type) {
96
+ case CHART_TYPE.LINE:
95
97
  case CHART_TYPE.BAR:
96
98
  {
97
99
  const {
@@ -71,9 +71,7 @@ class GroupBy extends Component {
71
71
  };
72
72
  this.getColumnOptions = columns => {
73
73
  const {
74
- chart: {
75
- config
76
- }
74
+ chart
77
75
  } = this.props;
78
76
  const newColumns = columns.map(column => {
79
77
  return {
@@ -87,7 +85,7 @@ class GroupBy extends Component {
87
85
  }, column.name))
88
86
  };
89
87
  });
90
- if (config.type === CHART_TYPE.TABLE) {
88
+ if ((chart === null || chart === void 0 ? void 0 : chart.config.type) === CHART_TYPE.TABLE) {
91
89
  newColumns.unshift({
92
90
  value: {
93
91
  key: '',
@@ -9,7 +9,6 @@ ChartUtils.calculateChart = (chart, value, callback) => {
9
9
  tables: value.tables,
10
10
  onSuccess: function (res) {
11
11
  let dataSources = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SQLStatisticsUtils.dataSources;
12
- console.log('res1', res);
13
12
  // Custom Bar
14
13
  if (Array.isArray(res)) {
15
14
  if (dataSources === OriginalDataUtils.dataSources) {
@@ -84,28 +84,103 @@ SQLStatisticsUtils.getGroupLabelFromDB = (cellValue, column, tables) => {
84
84
  }
85
85
  };
86
86
  SQLStatisticsUtils.formatedTableSqlRows = (chart, sqlRows, chartSQLMap, columnMap, tables) => {
87
- // Split multiple collaborators in a row
87
+ const {
88
+ config
89
+ } = chart;
88
90
  const {
89
91
  sqlGroupbyColumnKey,
90
- sqlSummaryColumnKey
92
+ sqlSummaryColumnKey,
93
+ summarySQLColumnName2ColumnKey
91
94
  } = chartSQLMap;
92
- const newSqlRows = sqlRows.slice(0);
93
- sqlRows.forEach((item, index) => {
94
- if (item[sqlGroupbyColumnKey].length > 1) {
95
- newSqlRows.splice(index, 1);
96
- item[sqlGroupbyColumnKey].forEach(jtem => {
97
- const rowIndex = newSqlRows.findIndex(rows => rows[sqlGroupbyColumnKey][0] === jtem);
98
- if (rowIndex !== -1) {
99
- newSqlRows[rowIndex][sqlSummaryColumnKey] = newSqlRows[rowIndex][sqlSummaryColumnKey] + 1;
100
- } else {
101
- newSqlRows.push({
102
- [sqlGroupbyColumnKey]: [jtem],
103
- [sqlSummaryColumnKey]: 1
104
- });
95
+ const newSqlRows = JSON.parse(JSON.stringify(sqlRows));
96
+ if (config.summary_type === CHART_SUMMARY_TYPE.COUNT) {
97
+ sqlRows.forEach((item, index) => {
98
+ const collaborators = item[sqlGroupbyColumnKey];
99
+ // Multiple collaborators
100
+ if (collaborators.length > 1) {
101
+ newSqlRows.splice(index, 1);
102
+ collaborators.forEach(jtem => {
103
+ const rowIndex = newSqlRows.findIndex(rows => rows[sqlGroupbyColumnKey][0] === jtem);
104
+ if (rowIndex !== -1) {
105
+ if (newSqlRows[rowIndex][sqlSummaryColumnKey]) {
106
+ newSqlRows[rowIndex][sqlSummaryColumnKey] = newSqlRows[rowIndex][sqlSummaryColumnKey] + 1;
107
+ }
108
+ } else {
109
+ const obj = {};
110
+ if (sqlGroupbyColumnKey) {
111
+ obj[sqlGroupbyColumnKey] = [jtem];
112
+ }
113
+ if (sqlSummaryColumnKey) {
114
+ obj[sqlSummaryColumnKey] = 1;
115
+ }
116
+ newSqlRows.push({
117
+ ...item,
118
+ ...obj
119
+ });
120
+ }
121
+ });
122
+ }
123
+ });
124
+ }
125
+ if (config.summary_type === CHART_SUMMARY_TYPE.ADVANCED) {
126
+ const summarySQLColumnName2ColumnKeys = Object.keys(summarySQLColumnName2ColumnKey);
127
+ sqlRows.forEach((item, index) => {
128
+ const collaborators = item[sqlGroupbyColumnKey];
129
+ // Multiple collaborators
130
+ if (collaborators.length > 1) {
131
+ newSqlRows.splice(index, 1);
132
+ collaborators.forEach(collaborator => {
133
+ const rowIndex = newSqlRows.findIndex(rows => rows[sqlGroupbyColumnKey][0] === collaborator);
134
+ if (rowIndex !== -1) {
135
+ summarySQLColumnName2ColumnKeys.forEach(key => {
136
+ let newKey = key;
137
+ // The avg is calculated by sum column
138
+ if (key.startsWith('AVG')) {
139
+ newKey = 'SUM' + key.slice(3);
140
+ }
141
+ // Update sum and count
142
+ if (newKey.startsWith('SUM') && newSqlRows[rowIndex][newKey]) {
143
+ newSqlRows[rowIndex][newKey] = newSqlRows[rowIndex][newKey] + item[newKey];
144
+ }
145
+ if (newSqlRows[rowIndex]['COUNT(*)']) {
146
+ newSqlRows[rowIndex]['COUNT(*)'] = newSqlRows[rowIndex]['COUNT(*)'] + 1;
147
+ }
148
+ });
149
+ } else {
150
+ const obj = {};
151
+ if (sqlGroupbyColumnKey) {
152
+ obj[sqlGroupbyColumnKey] = [collaborator];
153
+ }
154
+ summarySQLColumnName2ColumnKeys.forEach(key => {
155
+ let newKey = key;
156
+ // The avg is calculated by sum column
157
+ if (key.startsWith('AVG')) {
158
+ newKey = 'SUM' + key.slice(3);
159
+ }
160
+ // Update sum and count
161
+ if (newKey.startsWith('SUM')) {
162
+ obj[newKey] = item[newKey];
163
+ }
164
+ obj['COUNT(*)'] = 1;
165
+ });
166
+ newSqlRows.push({
167
+ ...item,
168
+ ...obj
169
+ });
170
+ }
171
+ });
172
+ }
173
+ });
174
+ newSqlRows.forEach(item => {
175
+ summarySQLColumnName2ColumnKeys.forEach(key => {
176
+ // Update avg
177
+ if (key.startsWith('AVG')) {
178
+ const newKey = 'SUM' + key.slice(3);
179
+ item[key] = item[newKey] / item['COUNT(*)'];
105
180
  }
106
181
  });
107
- }
108
- });
182
+ });
183
+ }
109
184
  return newSqlRows;
110
185
  };
111
186
  SQLStatisticsUtils.oneDimensionTableSQLResult2JavaScript = (chart, sqlRows, chartSQLMap, columnMap, tables) => {
@@ -122,7 +197,10 @@ SQLStatisticsUtils.oneDimensionTableSQLResult2JavaScript = (chart, sqlRows, char
122
197
  let pivot_columns = [];
123
198
  let pivot_rows = [];
124
199
  const isCount = summary_type === CHART_SUMMARY_TYPE.COUNT;
125
- const newSqlRows = _class.formatedTableSqlRows(chart, sqlRows, chartSQLMap, columnMap, tables);
200
+ let newSqlRows = sqlRows;
201
+ if (groupbyColumn.type === CellType.COLLABORATOR) {
202
+ newSqlRows = _class.formatedTableSqlRows(chart, sqlRows, chartSQLMap, columnMap, tables);
203
+ }
126
204
  if (isCount) {
127
205
  let allTotal = 0;
128
206
  newSqlRows.forEach(row => {
@@ -342,7 +420,6 @@ SQLStatisticsUtils.getAndUpdateTwoDimensionTotal = (pivot_columns_total, pivot_c
342
420
  return pivot_table_total;
343
421
  };
344
422
  SQLStatisticsUtils.twoDimensionTableSQLResult2JavaScript = (chart, sqlRows, chartSQLMap, columnMap, tables) => {
345
- const newSqlRows = _class.formatedTableSqlRows(chart, sqlRows, chartSQLMap, columnMap, tables);
346
423
  const {
347
424
  groupbyColumn,
348
425
  columnGroupbyColumn,
@@ -359,6 +436,10 @@ SQLStatisticsUtils.twoDimensionTableSQLResult2JavaScript = (chart, sqlRows, char
359
436
  } = chartSQLMap;
360
437
  if (!sqlColumnGroupbyColumnKey) return _class.oneDimensionTableSQLResult2JavaScript(chart, sqlRows, chartSQLMap, columnMap, tables);
361
438
  const summaryMethod = (summary_method || 'sum').toUpperCase();
439
+ let newSqlRows = sqlRows;
440
+ if (groupbyColumn.type === CellType.COLLABORATOR) {
441
+ newSqlRows = _class.formatedTableSqlRows(chart, sqlRows, chartSQLMap, columnMap, tables);
442
+ }
362
443
  let pivot_columns = [];
363
444
  let pivot_rows = [];
364
445
  let pivot_columns_total = {};
@@ -457,6 +457,16 @@ class ChartDataSQL {
457
457
  summary_column_names.push(column_name);
458
458
  }
459
459
  });
460
+
461
+ // groupby_column is COLLABORATOR , replace AVG with SUM, and add 'COUNT(*)'
462
+ if (groupby_column.type === CellType.COLLABORATOR) {
463
+ summary_column_names.forEach((item, index) => {
464
+ if (item.startsWith('AVG')) {
465
+ summary_column_names[index] = 'SUM' + item.slice(3);
466
+ }
467
+ });
468
+ summary_column_names.push('COUNT(*)');
469
+ }
460
470
  let summary_column_names_str = summary_column_names.join(', ');
461
471
  if (summary_column_names_str) {
462
472
  summary_column_names_str = ", ".concat(summary_column_names_str);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sea-chart",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "main": "./dist/index.js",
5
5
  "dependencies": {
6
6
  "@antv/data-set": "0.11.8",