sea-chart 0.0.31 → 0.0.32
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.
- package/dist/context.js +41 -14
- package/dist/settings/mirror-settings/data-settings.js +1 -1
- package/dist/settings/widgets/group-by.js +5 -3
- package/dist/utils/chart-utils/base-utils.js +10 -0
- package/dist/utils/chart-utils/index.js +2 -10
- package/dist/utils/chart-utils/sql-statistics-utils.js +95 -106
- package/dist/utils/index.js +0 -38
- package/dist/utils/map.js +1 -1
- package/dist/utils/sql/chart-data-sql.js +151 -195
- package/dist/utils/sql/column-2-sql-column.js +4 -1
- package/dist/view/wrapper/map.js +3 -5
- package/dist/view/wrapper/world-map.js +3 -2
- package/package.json +1 -1
package/dist/context.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getTableById } from 'dtable-utils';
|
|
2
2
|
import CollaboratorManager from './utils/collaborator-manager';
|
|
3
3
|
import { ChartDataSQL } from './utils';
|
|
4
|
-
import { CHART_TYPE_IMAGE } from './constants';
|
|
4
|
+
import { CHART_TYPE, CHART_TYPE_IMAGE } from './constants';
|
|
5
5
|
class Context {
|
|
6
6
|
constructor() {
|
|
7
7
|
this.queryChartResult = async _ref => {
|
|
@@ -32,28 +32,55 @@ class Context {
|
|
|
32
32
|
onFail && onFail(error);
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
const type = chart.config.type;
|
|
36
|
+
if (type === CHART_TYPE.BAR_CUSTOM) {
|
|
37
|
+
let allPromises = [];
|
|
38
|
+
Array.isArray(sql) && sql.forEach(item => {
|
|
39
|
+
if (item) {
|
|
40
|
+
const res = this.api.sqlQuery(item);
|
|
41
|
+
allPromises.push(res);
|
|
42
|
+
} else {
|
|
43
|
+
allPromises.push(new Promise((resolve, reject) => {
|
|
44
|
+
return resolve({
|
|
45
|
+
data: {
|
|
46
|
+
success: true,
|
|
47
|
+
results: []
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
let newRes = {
|
|
54
|
+
data: {
|
|
55
|
+
success: true,
|
|
56
|
+
results: []
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
return Promise.all(allPromises).then(allRes => {
|
|
60
|
+
if (!allRes.every(item => item.data.success)) {
|
|
61
|
+
onFail && onFail('Network_error');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
allRes.forEach(res => {
|
|
65
|
+
const {
|
|
66
|
+
results
|
|
67
|
+
} = res.data;
|
|
68
|
+
newRes.data.results.push(results);
|
|
43
69
|
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
70
|
+
onSuccess && onSuccess(newRes);
|
|
71
|
+
}).catch(error => {
|
|
72
|
+
onFail && onFail(error);
|
|
73
|
+
});
|
|
47
74
|
}
|
|
48
75
|
return this.api.sqlQuery(sql).then(res => {
|
|
49
76
|
onSuccess && onSuccess(res);
|
|
50
77
|
}).catch(error => {
|
|
51
78
|
var _error$response, _error$response$data;
|
|
52
79
|
// if geolocation format is wrong, still display the chart
|
|
53
|
-
if (
|
|
80
|
+
if (type.includes('map') && (error === null || error === void 0 ? void 0 : (_error$response = error.response) === null || _error$response === void 0 ? void 0 : (_error$response$data = _error$response.data) === null || _error$response$data === void 0 ? void 0 : _error$response$data.error_message.includes('invalid geolocation format'))) {
|
|
54
81
|
var _error$response2, _error$response2$data;
|
|
55
82
|
console.error(error === null || error === void 0 ? void 0 : (_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : (_error$response2$data = _error$response2.data) === null || _error$response2$data === void 0 ? void 0 : _error$response2$data.message);
|
|
56
|
-
onSuccess({
|
|
83
|
+
onSuccess && onSuccess({
|
|
57
84
|
data: {
|
|
58
85
|
results: [],
|
|
59
86
|
success: true
|
|
@@ -82,7 +82,7 @@ const DataSettings = _ref => {
|
|
|
82
82
|
label: intl.get('Statistic_field'),
|
|
83
83
|
selectedTableId: table_id,
|
|
84
84
|
selectedColumnKey: column_key,
|
|
85
|
-
|
|
85
|
+
isMirror: true,
|
|
86
86
|
onGroupByChange: onXAxisColumnChange
|
|
87
87
|
}), /*#__PURE__*/React.createElement(Switch, {
|
|
88
88
|
key: "x_axis_include_empty_cells",
|
|
@@ -61,12 +61,12 @@ class GroupBy extends Component {
|
|
|
61
61
|
this.getAvailableColumns = columns => {
|
|
62
62
|
const {
|
|
63
63
|
onlySupportDate,
|
|
64
|
-
|
|
64
|
+
isMirror,
|
|
65
65
|
onlySupportSingleSelect
|
|
66
66
|
} = this.props;
|
|
67
67
|
if (!columns || !Array.isArray(columns)) return [];
|
|
68
68
|
let newColumns = [];
|
|
69
|
-
if (
|
|
69
|
+
if (isMirror) {
|
|
70
70
|
newColumns = columns.filter(column => MIRROR_COLUMN_LIST.includes(column.type));
|
|
71
71
|
return newColumns;
|
|
72
72
|
}
|
|
@@ -163,8 +163,10 @@ class GroupBy extends Component {
|
|
|
163
163
|
};
|
|
164
164
|
this.renderGroupBy = () => {
|
|
165
165
|
const {
|
|
166
|
-
selectedColumnKey
|
|
166
|
+
selectedColumnKey,
|
|
167
|
+
isMirror
|
|
167
168
|
} = this.props;
|
|
169
|
+
if (isMirror) return null;
|
|
168
170
|
if (!selectedColumnKey) return null;
|
|
169
171
|
const groupbyColumn = getTableColumnByKey(this.selectedTable, selectedColumnKey);
|
|
170
172
|
if (!groupbyColumn) return null;
|
|
@@ -136,6 +136,9 @@ BaseUtils.getGroupColumn = (table, chart) => {
|
|
|
136
136
|
if (type === CHART_TYPE.TREND) {
|
|
137
137
|
return getTableColumnByKey(table, config.date_column_key);
|
|
138
138
|
}
|
|
139
|
+
if (type === CHART_TYPE.HEAT_MAP) {
|
|
140
|
+
return getTableColumnByKey(table, config.time_column_key);
|
|
141
|
+
}
|
|
139
142
|
return getTableColumnByKey(table, config.x_axis_column_key);
|
|
140
143
|
};
|
|
141
144
|
BaseUtils.getColumnGroupColumn = (table, chart) => {
|
|
@@ -154,6 +157,9 @@ BaseUtils.getColumnGroupColumn = (table, chart) => {
|
|
|
154
157
|
if ([CHART_TYPE.MIRROR].includes(type)) {
|
|
155
158
|
return getTableColumnByKey(table, config.group_column_key);
|
|
156
159
|
}
|
|
160
|
+
if (type === CHART_TYPE.SCATTER) {
|
|
161
|
+
return getTableColumnByKey(table, config.column_groupby_column_key);
|
|
162
|
+
}
|
|
157
163
|
return getTableColumnByKey(table, config.y_axis_summary_column_key);
|
|
158
164
|
};
|
|
159
165
|
BaseUtils.getSummaryColumn = (table, chart) => {
|
|
@@ -182,6 +188,10 @@ BaseUtils.getSummaryColumn = (table, chart) => {
|
|
|
182
188
|
{
|
|
183
189
|
return getTableColumnByKey(table, numeric_column_key);
|
|
184
190
|
}
|
|
191
|
+
case CHART_TYPE.SCATTER:
|
|
192
|
+
{
|
|
193
|
+
return getTableColumnByKey(table, config.y_axis_column_key);
|
|
194
|
+
}
|
|
185
195
|
default:
|
|
186
196
|
{
|
|
187
197
|
return getTableColumnByKey(table, summary_column_key);
|
|
@@ -12,16 +12,8 @@ ChartUtils.calculateChart = (chart, value, callback) => {
|
|
|
12
12
|
chart,
|
|
13
13
|
tables: value.tables,
|
|
14
14
|
onSuccess: function (res) {
|
|
15
|
+
var _res$data;
|
|
15
16
|
let dataSources = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SQLStatisticsUtils.dataSources;
|
|
16
|
-
// Custom Bar
|
|
17
|
-
if (Array.isArray(res)) {
|
|
18
|
-
if (dataSources === OriginalDataUtils.dataSources) {
|
|
19
|
-
OriginalDataUtils.calculateChart(chart, value, callback);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
SQLStatisticsUtils.calculateChart(chart, value, callback, res);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
17
|
const {
|
|
26
18
|
success,
|
|
27
19
|
error_message
|
|
@@ -34,7 +26,7 @@ ChartUtils.calculateChart = (chart, value, callback) => {
|
|
|
34
26
|
OriginalDataUtils.calculateChart(chart, value, callback);
|
|
35
27
|
return;
|
|
36
28
|
}
|
|
37
|
-
SQLStatisticsUtils.calculateChart(chart, value, callback, res);
|
|
29
|
+
SQLStatisticsUtils.calculateChart(chart, value, callback, (res === null || res === void 0 ? void 0 : (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.results) || []);
|
|
38
30
|
},
|
|
39
31
|
onFail: err => {
|
|
40
32
|
let errorMessage = String(err) || 'Network_error';
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
var _class;
|
|
2
2
|
import dayjs from 'dayjs';
|
|
3
3
|
import { CellType, MULTIPLE_CELL_VALUE_COLUMN_TYPE_MAP, getFormulaDisplayString, getPrecisionNumber, getTableById, getTableColumnByKey } from 'dtable-utils';
|
|
4
|
-
import { CHART_SUMMARY_TYPE, CHART_TYPE, SUPPORT_DATA_SORT_CHART_TYPES, LABEL_COLORS, TABLE_DIMENSIONS,
|
|
4
|
+
import { CHART_SUMMARY_TYPE, CHART_TYPE, SUPPORT_DATA_SORT_CHART_TYPES, LABEL_COLORS, TABLE_DIMENSIONS, Y_AXIS_TYPE_PREFIX } from '../../constants';
|
|
5
5
|
import { chartColumn2SqlColumn, summaryMethodColumn2SqlColumn } from '../sql';
|
|
6
6
|
import { getClientLinkDisplayString } from '../cell-format-utils';
|
|
7
7
|
import context from '../../context';
|
|
8
8
|
import { column2SqlColumn } from '../sql/column-2-sql-column';
|
|
9
|
-
import { formatNumericValue, getFormattedValue,
|
|
9
|
+
import { formatNumericValue, getFormattedValue, getSummaryResult } from '../column-utils';
|
|
10
10
|
import { getCompareDate } from '../trend-utils';
|
|
11
11
|
import intl from '../../intl';
|
|
12
12
|
import BaseUtils from './base-utils';
|
|
13
|
-
class SQLStatisticsUtils {
|
|
13
|
+
class SQLStatisticsUtils {
|
|
14
|
+
constructor() {
|
|
15
|
+
this._get_completeness_name = (row, column) => {
|
|
16
|
+
let value = row[column.key];
|
|
17
|
+
if (Array.isArray(value)) {
|
|
18
|
+
value = value.join('、');
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
14
24
|
_class = SQLStatisticsUtils;
|
|
15
25
|
SQLStatisticsUtils.dataSources = 'sql_statistics';
|
|
16
26
|
SQLStatisticsUtils.getGroupLabelFromDB = (cellValue, column, tables) => {
|
|
@@ -630,23 +640,39 @@ SQLStatisticsUtils.basicNumberCardSQLResult2JavaScript = (chart, sqlRows, chartS
|
|
|
630
640
|
}
|
|
631
641
|
return 0;
|
|
632
642
|
};
|
|
633
|
-
SQLStatisticsUtils.customChartSQLResult2JavaScript = (chart, sqlRows, chartSQLMap, columnMap, tables,
|
|
643
|
+
SQLStatisticsUtils.customChartSQLResult2JavaScript = (chart, sqlRows, chartSQLMap, columnMap, tables, _ref4) => {
|
|
644
|
+
let {
|
|
645
|
+
index
|
|
646
|
+
} = _ref4;
|
|
634
647
|
const {
|
|
635
648
|
table_id,
|
|
636
|
-
x_axis_column_key,
|
|
637
649
|
x_axis_date_granularity,
|
|
638
650
|
x_axis_geolocation_granularity,
|
|
639
|
-
x_axis_include_empty
|
|
651
|
+
x_axis_include_empty,
|
|
652
|
+
y_axises
|
|
640
653
|
} = chart.config;
|
|
641
654
|
const {
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
numericColumns,
|
|
645
|
-
groupColumnNames,
|
|
646
|
-
yAxisType
|
|
647
|
-
} = params;
|
|
655
|
+
groupbyColumn
|
|
656
|
+
} = columnMap;
|
|
648
657
|
const table = getTableById(tables, table_id);
|
|
649
|
-
const
|
|
658
|
+
const stack = y_axises[index];
|
|
659
|
+
if (!stack) return [];
|
|
660
|
+
const {
|
|
661
|
+
column_groupby_numeric_columns
|
|
662
|
+
} = stack;
|
|
663
|
+
const y_axis_type = "".concat(Y_AXIS_TYPE_PREFIX).concat(index);
|
|
664
|
+
let summaryMethods = [];
|
|
665
|
+
let originalMethods = [];
|
|
666
|
+
let groupColumnNames = [];
|
|
667
|
+
let numericColumns = [];
|
|
668
|
+
column_groupby_numeric_columns.forEach(item => {
|
|
669
|
+
const numericColumn = getTableColumnByKey(table, item.column_key);
|
|
670
|
+
const groupColumnName = numericColumn.name;
|
|
671
|
+
numericColumns.push(numericColumn);
|
|
672
|
+
groupColumnNames.push(groupColumnName);
|
|
673
|
+
summaryMethods.push(summaryMethodColumn2SqlColumn(item.summary_method.toUpperCase(), numericColumn).key);
|
|
674
|
+
originalMethods.push(item.summary_method);
|
|
675
|
+
});
|
|
650
676
|
const {
|
|
651
677
|
key: sqlGroupbyColumnKey
|
|
652
678
|
} = column2SqlColumn(groupbyColumn, {
|
|
@@ -659,21 +685,19 @@ SQLStatisticsUtils.customChartSQLResult2JavaScript = (chart, sqlRows, chartSQLMa
|
|
|
659
685
|
const label = _class.getGroupLabelFromDB(cellValue, groupbyColumn, tables);
|
|
660
686
|
const isEmpty = !label;
|
|
661
687
|
const groupItems = [];
|
|
662
|
-
|
|
663
|
-
if (!x_axis_include_empty && isEmpty)
|
|
664
|
-
|
|
665
|
-
}
|
|
666
|
-
let value = row[groupMethods[index]] || 0;
|
|
688
|
+
summaryMethods.forEach((summaryMethod, index) => {
|
|
689
|
+
if (!x_axis_include_empty && isEmpty) return;
|
|
690
|
+
let value = row[summaryMethod] || 0;
|
|
667
691
|
let formatted_value = value;
|
|
668
692
|
value = formatNumericValue(value, numericColumns[index]);
|
|
669
|
-
formatted_value = getFormattedValue(value, numericColumns, originalMethods[index]);
|
|
693
|
+
formatted_value = getFormattedValue(value, numericColumns[index], originalMethods[index]);
|
|
670
694
|
groupItems.push({
|
|
671
695
|
name: label,
|
|
672
696
|
value,
|
|
673
697
|
formatted_value,
|
|
674
698
|
group_name: groupColumnNames[index],
|
|
675
699
|
original_name: row[groupbyColumn.key],
|
|
676
|
-
y_axis_type:
|
|
700
|
+
y_axis_type: y_axis_type
|
|
677
701
|
});
|
|
678
702
|
});
|
|
679
703
|
result = result.concat(groupItems);
|
|
@@ -681,46 +705,35 @@ SQLStatisticsUtils.customChartSQLResult2JavaScript = (chart, sqlRows, chartSQLMa
|
|
|
681
705
|
return result;
|
|
682
706
|
};
|
|
683
707
|
SQLStatisticsUtils.compareSQLResult2Javascript = (chart, sqlRows, chartSQLMap, columnMap, tables) => {
|
|
708
|
+
const {
|
|
709
|
+
groupbyColumn,
|
|
710
|
+
summaryColumn
|
|
711
|
+
} = columnMap;
|
|
712
|
+
const {
|
|
713
|
+
sqlGroupbyColumnKey,
|
|
714
|
+
sqlSummaryColumnKey
|
|
715
|
+
} = chartSQLMap;
|
|
684
716
|
const {
|
|
685
717
|
config
|
|
686
718
|
} = chart;
|
|
687
719
|
const {
|
|
688
|
-
table_id,
|
|
689
720
|
x_axis_date_range_start,
|
|
690
721
|
x_axis_date_range_end,
|
|
691
722
|
x_axis_compared_date_range_start,
|
|
692
723
|
x_axis_compared_date_range_end,
|
|
693
724
|
y_axis_summary_type,
|
|
694
725
|
y_axis_summary_method,
|
|
695
|
-
x_axis_column_key,
|
|
696
|
-
y_axis_column_key,
|
|
697
|
-
x_axis_geolocation_granularity,
|
|
698
726
|
display_increase
|
|
699
727
|
} = config;
|
|
700
728
|
const groupName1 = "".concat(x_axis_date_range_start, " - ").concat(x_axis_date_range_end);
|
|
701
729
|
const groupName2 = "".concat(x_axis_compared_date_range_start, " - ").concat(x_axis_compared_date_range_end);
|
|
702
730
|
const dateRangeResult = new Map();
|
|
703
731
|
let dateComparedResult = new Map();
|
|
704
|
-
const selectedTable = getTableById(tables, table_id);
|
|
705
|
-
const selectedColumn = getColumnByKey(x_axis_column_key, selectedTable.columns);
|
|
706
|
-
const groupName = getSqlGroup(selectedColumn, {
|
|
707
|
-
'date_granularity': 'day',
|
|
708
|
-
'geolocation_granularity': x_axis_geolocation_granularity
|
|
709
|
-
});
|
|
710
|
-
let summaryColumnName = "".concat(selectedColumn.name);
|
|
711
|
-
let selectedSummaryColumn = {};
|
|
712
732
|
const isAdvanced = y_axis_summary_type === CHART_SUMMARY_TYPE.ADVANCED;
|
|
713
|
-
if (isAdvanced) {
|
|
714
|
-
selectedSummaryColumn = getColumnByKey(y_axis_column_key, selectedTable.columns);
|
|
715
|
-
if (!selectedSummaryColumn) return [];
|
|
716
|
-
summaryColumnName = "".concat(selectedSummaryColumn.name);
|
|
717
|
-
}
|
|
718
|
-
const method = isAdvanced ? DTABLE_DB_SUMMARY_METHOD[y_axis_summary_method] : DTABLE_DB_SUMMARY_METHOD.COUNT;
|
|
719
|
-
const valueKey = isAdvanced ? "".concat(method, "(").concat(summaryColumnName, ")") : "".concat(method, "(").concat(selectedColumn.name, ")");
|
|
720
733
|
sqlRows.forEach(item => {
|
|
721
|
-
const name = item[
|
|
722
|
-
const label = _class.getGroupLabelFromDB(name,
|
|
723
|
-
const value = item[
|
|
734
|
+
const name = item[sqlGroupbyColumnKey];
|
|
735
|
+
const label = _class.getGroupLabelFromDB(name, groupbyColumn, tables);
|
|
736
|
+
const value = item[sqlSummaryColumnKey];
|
|
724
737
|
if (name >= x_axis_date_range_start && name <= x_axis_date_range_end) {
|
|
725
738
|
const currentValue = dateRangeResult.get(label);
|
|
726
739
|
if (!currentValue) {
|
|
@@ -755,13 +768,13 @@ SQLStatisticsUtils.compareSQLResult2Javascript = (chart, sqlRows, chartSQLMap, c
|
|
|
755
768
|
});
|
|
756
769
|
let comparedResult = [];
|
|
757
770
|
let rangeResult = [];
|
|
758
|
-
const data =
|
|
771
|
+
const data = (summaryColumn === null || summaryColumn === void 0 ? void 0 : summaryColumn.data) || {};
|
|
759
772
|
for (let item of dateRangeResult) {
|
|
760
773
|
let value = item[1];
|
|
761
774
|
let formatted_value = value;
|
|
762
775
|
if (isAdvanced) {
|
|
763
776
|
value = getSummaryResult(item[1], y_axis_summary_method, data.precision);
|
|
764
|
-
formatted_value = getFormattedValue(value,
|
|
777
|
+
formatted_value = getFormattedValue(value, summaryColumn, y_axis_summary_method);
|
|
765
778
|
}
|
|
766
779
|
rangeResult.push({
|
|
767
780
|
name: item[0],
|
|
@@ -781,7 +794,7 @@ SQLStatisticsUtils.compareSQLResult2Javascript = (chart, sqlRows, chartSQLMap, c
|
|
|
781
794
|
let formatted_value = value;
|
|
782
795
|
if (isAdvanced) {
|
|
783
796
|
value = getSummaryResult(item[1], y_axis_summary_method, data.precision);
|
|
784
|
-
formatted_value = getFormattedValue(value,
|
|
797
|
+
formatted_value = getFormattedValue(value, summaryColumn, y_axis_summary_method);
|
|
785
798
|
}
|
|
786
799
|
const newItem = {
|
|
787
800
|
name: dateRangeItem.name,
|
|
@@ -1115,26 +1128,19 @@ SQLStatisticsUtils.groupingChartSQLResult2JavaScript = (chart, sqlRows, chartSQL
|
|
|
1115
1128
|
return _class.groupingTwoDimensionChartSQLResult2JavaScript(chart, sqlRows, chartSQLMap, columnMap, tables);
|
|
1116
1129
|
};
|
|
1117
1130
|
SQLStatisticsUtils.heatMapChartSQLResult2JavaScript = (chart, sqlRows, chartSQLMap, columnMap, tables) => {
|
|
1118
|
-
const {
|
|
1119
|
-
config
|
|
1120
|
-
} = chart;
|
|
1121
|
-
const {
|
|
1122
|
-
time_column_key,
|
|
1123
|
-
summary_type
|
|
1124
|
-
} = config;
|
|
1125
1131
|
const {
|
|
1126
1132
|
summaryColumn
|
|
1127
1133
|
} = columnMap;
|
|
1128
1134
|
const {
|
|
1135
|
+
sqlGroupbyColumnKey,
|
|
1129
1136
|
sqlSummaryColumnKey
|
|
1130
1137
|
} = chartSQLMap;
|
|
1131
1138
|
let result = [];
|
|
1132
|
-
const isAdvanced = summary_type === CHART_SUMMARY_TYPE.ADVANCED;
|
|
1133
1139
|
sqlRows.forEach(item => {
|
|
1134
|
-
const currentValue = item[
|
|
1135
|
-
if (currentValue) {
|
|
1140
|
+
const currentValue = item[sqlGroupbyColumnKey];
|
|
1141
|
+
if (currentValue || currentValue === 0) {
|
|
1136
1142
|
let value = item[sqlSummaryColumnKey];
|
|
1137
|
-
if (
|
|
1143
|
+
if (summaryColumn) {
|
|
1138
1144
|
value = formatNumericValue(value, summaryColumn);
|
|
1139
1145
|
}
|
|
1140
1146
|
const name = typeof currentValue === 'string' ? currentValue : currentValue.country_region;
|
|
@@ -1161,13 +1167,9 @@ SQLStatisticsUtils.heatMapChartSQLResult2JavaScript = (chart, sqlRows, chartSQLM
|
|
|
1161
1167
|
}
|
|
1162
1168
|
});
|
|
1163
1169
|
data.sort((current, next) => {
|
|
1164
|
-
if (current.year > next.year)
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
return 1;
|
|
1168
|
-
} else {
|
|
1169
|
-
return 0;
|
|
1170
|
-
}
|
|
1170
|
+
if (current.year > next.year) return -1;
|
|
1171
|
+
if (current.year < next.year) return 1;
|
|
1172
|
+
return 0;
|
|
1171
1173
|
});
|
|
1172
1174
|
return {
|
|
1173
1175
|
data,
|
|
@@ -1412,7 +1414,7 @@ SQLStatisticsUtils.sqlResult2JavaScript = (chart, sqlRows, chartSQLMap, columnMa
|
|
|
1412
1414
|
}
|
|
1413
1415
|
}
|
|
1414
1416
|
};
|
|
1415
|
-
SQLStatisticsUtils.completenessSQlResult = (chart, sqlRows,
|
|
1417
|
+
SQLStatisticsUtils.completenessSQlResult = (chart, sqlRows, chartSQLMap, tables) => {
|
|
1416
1418
|
const {
|
|
1417
1419
|
config: {
|
|
1418
1420
|
type
|
|
@@ -1422,7 +1424,7 @@ SQLStatisticsUtils.completenessSQlResult = (chart, sqlRows, sqlStatistics, table
|
|
|
1422
1424
|
const {
|
|
1423
1425
|
sqlColumns,
|
|
1424
1426
|
sqlColumnGroupByColumnKey
|
|
1425
|
-
} =
|
|
1427
|
+
} = chartSQLMap;
|
|
1426
1428
|
const {
|
|
1427
1429
|
name_column,
|
|
1428
1430
|
completed_column,
|
|
@@ -1433,19 +1435,11 @@ SQLStatisticsUtils.completenessSQlResult = (chart, sqlRows, sqlStatistics, table
|
|
|
1433
1435
|
// format the fetched value
|
|
1434
1436
|
BaseUtils.updateTableViewList(sqlRows, name_column, name_column.key, 'color');
|
|
1435
1437
|
if (sqlColumnGroupByColumnKey) BaseUtils.updateTableViewList(sqlRows, column_groupby_column, sqlColumnGroupByColumnKey, 'color');
|
|
1436
|
-
function getFormatedKey(row, column) {
|
|
1437
|
-
// const newKey = column.name;
|
|
1438
|
-
let value = row[column.key];
|
|
1439
|
-
if (Array.isArray(value)) {
|
|
1440
|
-
value = value.join('、');
|
|
1441
|
-
}
|
|
1442
|
-
return value;
|
|
1443
|
-
}
|
|
1444
1438
|
const res = [];
|
|
1445
|
-
let
|
|
1439
|
+
let summedSqlRows;
|
|
1446
1440
|
if (!isGroup) {
|
|
1447
1441
|
const sumSqlRows = sqlRows.reduce((acc, row) => {
|
|
1448
|
-
const nameValue =
|
|
1442
|
+
const nameValue = _class._get_completeness_name(row, name_column);
|
|
1449
1443
|
if (!acc[nameValue]) {
|
|
1450
1444
|
acc[nameValue] = row;
|
|
1451
1445
|
} else {
|
|
@@ -1457,10 +1451,10 @@ SQLStatisticsUtils.completenessSQlResult = (chart, sqlRows, sqlStatistics, table
|
|
|
1457
1451
|
}
|
|
1458
1452
|
return acc;
|
|
1459
1453
|
}, {});
|
|
1460
|
-
|
|
1454
|
+
summedSqlRows = Object.values(sumSqlRows);
|
|
1461
1455
|
} else {
|
|
1462
1456
|
const sumSqlRowsWithGroupBy = sqlRows.reduce((acc, row) => {
|
|
1463
|
-
const nameValue =
|
|
1457
|
+
const nameValue = _class._get_completeness_name(row, name_column);
|
|
1464
1458
|
const groupby = row[sqlColumnGroupByColumnKey];
|
|
1465
1459
|
const key = "".concat(nameValue, "_").concat(groupby);
|
|
1466
1460
|
if (!acc[key]) {
|
|
@@ -1475,10 +1469,10 @@ SQLStatisticsUtils.completenessSQlResult = (chart, sqlRows, sqlStatistics, table
|
|
|
1475
1469
|
}
|
|
1476
1470
|
return acc;
|
|
1477
1471
|
}, {});
|
|
1478
|
-
|
|
1472
|
+
summedSqlRows = Object.values(sumSqlRowsWithGroupBy);
|
|
1479
1473
|
}
|
|
1480
|
-
|
|
1481
|
-
const nameValue =
|
|
1474
|
+
summedSqlRows.forEach(row => {
|
|
1475
|
+
const nameValue = _class._get_completeness_name(row, name_column);
|
|
1482
1476
|
let targetValue;
|
|
1483
1477
|
let completedValue;
|
|
1484
1478
|
let groupby;
|
|
@@ -1487,8 +1481,8 @@ SQLStatisticsUtils.completenessSQlResult = (chart, sqlRows, sqlStatistics, table
|
|
|
1487
1481
|
completedValue = row["SUM(".concat(completed_column.name, ")")];
|
|
1488
1482
|
groupby = row[sqlColumnGroupByColumnKey] || intl.get('Empty');
|
|
1489
1483
|
} else {
|
|
1490
|
-
completedValue =
|
|
1491
|
-
targetValue =
|
|
1484
|
+
completedValue = _class._get_completeness_name(row, completed_column);
|
|
1485
|
+
targetValue = _class._get_completeness_name(row, target_column);
|
|
1492
1486
|
}
|
|
1493
1487
|
let completedRate;
|
|
1494
1488
|
if (!targetValue && completedValue) {
|
|
@@ -1526,26 +1520,21 @@ SQLStatisticsUtils.completenessSQlResult = (chart, sqlRows, sqlStatistics, table
|
|
|
1526
1520
|
return res;
|
|
1527
1521
|
};
|
|
1528
1522
|
SQLStatisticsUtils.scatterSQLResult2JavaScript = (chart, sqlRows, chartSQLMap, columnMap, tables) => {
|
|
1529
|
-
const {
|
|
1530
|
-
x_axis_column_key,
|
|
1531
|
-
y_axis_column_key,
|
|
1532
|
-
column_groupby_column_key,
|
|
1533
|
-
table_id
|
|
1534
|
-
} = chart.config;
|
|
1535
1523
|
const {
|
|
1536
1524
|
sqlXColumnKey,
|
|
1537
1525
|
sqlYColumnKey,
|
|
1538
1526
|
sqlColumnGroupbyColumnKey
|
|
1539
1527
|
} = chartSQLMap;
|
|
1540
|
-
const
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1528
|
+
const {
|
|
1529
|
+
groupbyColumn,
|
|
1530
|
+
columnGroupbyColumn,
|
|
1531
|
+
summaryColumn
|
|
1532
|
+
} = columnMap;
|
|
1544
1533
|
|
|
1545
1534
|
// format sql rows
|
|
1546
|
-
BaseUtils.updateTableViewList(sqlRows,
|
|
1547
|
-
BaseUtils.updateTableViewList(sqlRows,
|
|
1548
|
-
if (sqlColumnGroupbyColumnKey) BaseUtils.updateTableViewList(sqlRows,
|
|
1535
|
+
BaseUtils.updateTableViewList(sqlRows, groupbyColumn, groupbyColumn.key, 'color');
|
|
1536
|
+
BaseUtils.updateTableViewList(sqlRows, summaryColumn, summaryColumn.key, 'color');
|
|
1537
|
+
if (sqlColumnGroupbyColumnKey) BaseUtils.updateTableViewList(sqlRows, columnGroupbyColumn, sqlColumnGroupbyColumnKey, 'color');
|
|
1549
1538
|
const res = [];
|
|
1550
1539
|
sqlRows.forEach(row => {
|
|
1551
1540
|
const xValue = row[sqlXColumnKey];
|
|
@@ -1607,7 +1596,7 @@ SQLStatisticsUtils.worldMapSQLResult2JavaScript = (chart, sqlRows, chartSQLMap,
|
|
|
1607
1596
|
});
|
|
1608
1597
|
return result;
|
|
1609
1598
|
};
|
|
1610
|
-
SQLStatisticsUtils.calculateChart = (chart, value, callback,
|
|
1599
|
+
SQLStatisticsUtils.calculateChart = (chart, value, callback, sqlRows) => {
|
|
1611
1600
|
const {
|
|
1612
1601
|
tables
|
|
1613
1602
|
} = value;
|
|
@@ -1650,14 +1639,15 @@ SQLStatisticsUtils.calculateChart = (chart, value, callback, res) => {
|
|
|
1650
1639
|
const tipMessage = 'There_are_no_statistic_results_yet';
|
|
1651
1640
|
|
|
1652
1641
|
// Custom Bar
|
|
1653
|
-
if (
|
|
1642
|
+
if (chartType === CHART_TYPE.BAR_CUSTOM) {
|
|
1654
1643
|
const result = [];
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1644
|
+
sqlRows.forEach((item, index) => {
|
|
1645
|
+
if (item.length !== 0) {
|
|
1646
|
+
const chartResult = _class.sqlResult2JavaScript(newChart, item, chartSQLMap, columnMap, tables, {
|
|
1647
|
+
index
|
|
1648
|
+
});
|
|
1649
|
+
result.push(...chartResult.result);
|
|
1650
|
+
}
|
|
1661
1651
|
});
|
|
1662
1652
|
if (result.length === 0) {
|
|
1663
1653
|
callback && callback('', tipMessage, null);
|
|
@@ -1673,15 +1663,14 @@ SQLStatisticsUtils.calculateChart = (chart, value, callback, res) => {
|
|
|
1673
1663
|
});
|
|
1674
1664
|
return;
|
|
1675
1665
|
}
|
|
1676
|
-
|
|
1677
|
-
results: sqlRows
|
|
1678
|
-
} = res.data;
|
|
1666
|
+
|
|
1679
1667
|
// map is special, still need to show map even data is empty
|
|
1680
1668
|
if (!Array.isArray(sqlRows) || sqlRows.length === 0 && !chartType.includes('map')) {
|
|
1681
1669
|
callback && callback('', tipMessage, null);
|
|
1682
1670
|
return;
|
|
1683
1671
|
}
|
|
1684
1672
|
const chartResult = _class.sqlResult2JavaScript(newChart, sqlRows, chartSQLMap, columnMap, tables);
|
|
1673
|
+
|
|
1685
1674
|
// map is special
|
|
1686
1675
|
if (BaseUtils.imEmptyChartResult(chartResult) && !chartType.includes('map')) {
|
|
1687
1676
|
callback && callback('', tipMessage, null);
|
package/dist/utils/index.js
CHANGED
|
@@ -11,44 +11,6 @@ export { getDateColumnFormat, isCheckboxColumn, getColumnByKey, getColumnByName,
|
|
|
11
11
|
export { generatorKey } from './key-generator';
|
|
12
12
|
export { translateCalendar } from './date-translate';
|
|
13
13
|
export { isFunction } from './common-utils';
|
|
14
|
-
function removeStrBeforeMedia(url) {
|
|
15
|
-
const mediaIndex = url.indexOf('/media/');
|
|
16
|
-
if (mediaIndex !== -1) {
|
|
17
|
-
return url.substring(mediaIndex);
|
|
18
|
-
}
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// don't use it unless on map json query
|
|
23
|
-
export const getMediaUrlForMap = () => {
|
|
24
|
-
let {
|
|
25
|
-
mediaUrl,
|
|
26
|
-
server
|
|
27
|
-
} = window.seaChartConfig;
|
|
28
|
-
|
|
29
|
-
// proxy to dev server to aviod CORS
|
|
30
|
-
if (process.env.NODE_ENV === 'development' && server.includes('dev.seatable.cn')) {
|
|
31
|
-
server = process.env.DEV_SERVER_URL;
|
|
32
|
-
}
|
|
33
|
-
if (mediaUrl.startsWith('http')) {
|
|
34
|
-
mediaUrl = removeStrBeforeMedia(mediaUrl);
|
|
35
|
-
if (!mediaUrl) {
|
|
36
|
-
throw new Error('on getMediaUrl: mediaUrl is not valid');
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return "".concat(server).concat(mediaUrl);
|
|
40
|
-
};
|
|
41
|
-
export const getMediaUrl = () => {
|
|
42
|
-
const {
|
|
43
|
-
media,
|
|
44
|
-
server
|
|
45
|
-
} = window.seaChartConfig;
|
|
46
|
-
if (media.startsWith('http')) {
|
|
47
|
-
return media;
|
|
48
|
-
} else {
|
|
49
|
-
return server + media;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
14
|
export const getGeoGranularityByLevel = mapLevel => {
|
|
53
15
|
switch (mapLevel) {
|
|
54
16
|
case MAP_LEVEL.PROVINCE:
|
package/dist/utils/map.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GEOLOCATION_GRANULARITY,
|
|
1
|
+
import { GEOLOCATION_GRANULARITY, MAP_LEVEL, MUNICIPALITIES, regions } from '../constants';
|
|
2
2
|
const COUNTY_SCALE_WIDTH = 5.95;
|
|
3
3
|
const COUNTY_SCALE_HEIGHT = 4.37;
|
|
4
4
|
export const getGeoGranularityByLevel = mapLevel => {
|