dtable-statistic 4.0.6 → 4.0.8
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/es/assets/css/dashboard.css +22 -0
- package/es/calculator/basic-chart-calculator.js +27 -18
- package/es/calculator/combination-calculator.js +34 -9
- package/es/calculator/compare-bar-calculator.js +37 -30
- package/es/calculator/heat-map-calculator.js +25 -14
- package/es/calculator/map-calculator.js +25 -14
- package/es/calculator/mirror-calculator.js +29 -14
- package/es/calculator/pivot-table-calculator.js +132 -76
- package/es/calculator/workers/basic-chart-calculator-worker.js +21 -6
- package/es/calculator/workers/combination-calculator-worker.js +20 -5
- package/es/calculator/workers/compare-bar-chart-calculator-worker.js +12 -6
- package/es/calculator/workers/mirror-calculator-worker.js +15 -6
- package/es/calculator/workers/pivot-table-calculator-worker.js +97 -44
- package/es/calculator/world-map-calculator.js +25 -14
- package/es/components/dialog/enlarged-chart-dialog.js +2 -2
- package/es/components/dialog/statistic-record-dialog/index.css +2 -0
- package/es/components/dialog/statistic-record-dialog/index.js +80 -52
- package/es/constants/index.js +30 -29
- package/es/dashboard.js +57 -43
- package/es/desktop-dashboard.js +21 -56
- package/es/index.js +34 -2
- package/es/locale/lang/de.js +7 -3
- package/es/locale/lang/en.js +5 -1
- package/es/locale/lang/fr.js +7 -3
- package/es/locale/lang/zh_CN.js +5 -1
- package/es/mobile-dashboard.js +5 -5
- package/es/model/horizontal-bar-group.js +2 -0
- package/es/stat-editor/stat-settings/advance-chart-settings/index.js +1 -2
- package/es/stat-editor/stat-settings/advance-chart-settings/summary-settings.js +1 -1
- package/es/stat-editor/stat-settings/basic-chart-settings/style-setting/horizontal-bar-chart-style.js +20 -3
- package/es/stat-editor/stat-settings/basic-chart-settings/summary-settings.js +2 -8
- package/es/stat-editor/stat-settings/public-setting/type-settings/index.js +23 -2
- package/es/stat-list/chart-preview.js +3 -4
- package/es/stat-list/index.js +10 -4
- package/es/stat-view/area-chart.js +177 -162
- package/es/stat-view/bar-chart.js +221 -222
- package/es/stat-view/base-chart.js +79 -7
- package/es/stat-view/basic-number-card.js +11 -19
- package/es/stat-view/combination-chart.js +100 -83
- package/es/stat-view/compare-chart.js +133 -144
- package/es/stat-view/completeness-chart.js +108 -102
- package/es/stat-view/custom-bar.js +79 -99
- package/es/stat-view/dashboard-chart.js +57 -57
- package/es/stat-view/heat-map.js +13 -32
- package/es/stat-view/horizontal-bar-chart.js +200 -230
- package/es/stat-view/index.js +2 -2
- package/es/stat-view/line-chart.js +162 -158
- package/es/stat-view/map.js +26 -40
- package/es/stat-view/mirror.js +88 -94
- package/es/stat-view/pie-chart.js +11 -39
- package/es/stat-view/pivot-table/index.js +4 -16
- package/es/stat-view/pivot-table/one-dimension-table-no-numeric-columns.js +36 -23
- package/es/stat-view/pivot-table/one-dimension-table-with-numeric-columns.js +11 -5
- package/es/stat-view/pivot-table/pivot-table-display-name.js +206 -0
- package/es/stat-view/pivot-table/two-dimension-table.js +104 -60
- package/es/stat-view/ring-chart.js +24 -42
- package/es/stat-view/scatter-chart.js +4 -21
- package/es/stat-view/treemap-chart.js +3 -12
- package/es/stat-view/trend-chart.js +6 -17
- package/es/stat-view/world-map.js +39 -50
- package/es/tabs/tab.js +2 -1
- package/es/utils/collaborator.js +9 -0
- package/es/utils/common-utils.js +24 -6
- package/es/utils/index.js +1 -1
- package/es/utils/sql-utils.js +10 -9
- package/es/utils/stat-utils.js +8 -5
- package/package.json +1 -1
|
@@ -6,19 +6,16 @@ import React from 'react';
|
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
7
|
import DataSet from '@antv/data-set';
|
|
8
8
|
import intl from 'react-intl-universal';
|
|
9
|
-
import { TableUtils
|
|
9
|
+
import { TableUtils } from 'dtable-store';
|
|
10
10
|
import BaseChart from './base-chart';
|
|
11
11
|
import { Chart } from '../custom-g2';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { getChartDisplayLabels, getChartGroups } from '../utils/basic-chart-utils';
|
|
12
|
+
import { getCurrentTheme, sortDataByGroupSum } from '../utils/common-utils';
|
|
13
|
+
import { getChartGroups } from '../utils/basic-chart-utils';
|
|
15
14
|
import { getConvertedColorRules, getLabelColor } from '../utils/color-utils';
|
|
16
|
-
import { EMPTY_NAME, DEFAULT_NUMBER_FORMAT_OBJECT, SUMMARY_TYPE, STATISTICS_COUNT_SHOW,
|
|
15
|
+
import { EMPTY_NAME, DEFAULT_NUMBER_FORMAT_OBJECT, SUMMARY_TYPE, STATISTICS_COUNT_SHOW, LABEL_CONFIG_CHANGED, STAT_TYPE, TITLE_AMOUNT, TYPE_COLOR_USING, STATISTICS_COUNT_TYPE } from '../constants';
|
|
17
16
|
var propTypes = {
|
|
18
17
|
isPreview: PropTypes.bool,
|
|
19
|
-
isEnlarge: PropTypes.bool,
|
|
20
18
|
isEdit: PropTypes.bool,
|
|
21
|
-
theme: PropTypes.string,
|
|
22
19
|
colorThemeName: PropTypes.string,
|
|
23
20
|
statItem: PropTypes.object,
|
|
24
21
|
chartCalculator: PropTypes.object,
|
|
@@ -36,64 +33,43 @@ var BarChart = /*#__PURE__*/function (_BaseChart) {
|
|
|
36
33
|
_this.drawChart = function (originalData) {
|
|
37
34
|
var _this$props = _this.props,
|
|
38
35
|
getTableById = _this$props.getTableById,
|
|
39
|
-
isPreview = _this$props.isPreview,
|
|
40
36
|
statItem = _this$props.statItem,
|
|
41
|
-
isEnlarge = _this$props.isEnlarge,
|
|
42
|
-
theme = _this$props.theme,
|
|
43
37
|
colorThemeName = _this$props.colorThemeName;
|
|
44
|
-
var
|
|
45
|
-
|
|
38
|
+
var type = statItem.type,
|
|
39
|
+
table_id = statItem.table_id,
|
|
40
|
+
summary_type = statItem.summary_type,
|
|
41
|
+
y_axis_column_key = statItem.y_axis_column_key,
|
|
42
|
+
y_axis_summary_type = statItem.y_axis_summary_type,
|
|
43
|
+
summary_method = statItem.summary_method,
|
|
44
|
+
y_axis_summary_method = statItem.y_axis_summary_method,
|
|
45
|
+
column_groupby_column_key = statItem.column_groupby_column_key,
|
|
46
|
+
column_groupby_multiple_numeric_column = statItem.column_groupby_multiple_numeric_column,
|
|
46
47
|
sort_type = statItem.sort_type;
|
|
47
|
-
var currentTheme = getCurrentTheme(colorThemeName);
|
|
48
48
|
var data = originalData;
|
|
49
49
|
if (type == STAT_TYPE.BAR_STACK && sort_type) {
|
|
50
50
|
data = sortDataByGroupSum(originalData, sort_type);
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
_this.chart = new Chart({
|
|
54
|
-
container: _this.container,
|
|
55
|
-
autoFit: true,
|
|
56
|
-
appendPadding: [display_data ? 17 : 0, 0, 0, 0]
|
|
57
|
-
});
|
|
58
|
-
} else {
|
|
59
|
-
_this.chart = new Chart({
|
|
60
|
-
container: _this.container,
|
|
61
|
-
autoFit: true,
|
|
62
|
-
height: 400,
|
|
63
|
-
width: 700,
|
|
64
|
-
appendPadding: [display_data ? 17 : 0, 0, 0, 0]
|
|
65
|
-
});
|
|
66
|
-
}
|
|
52
|
+
_this.initChartHandler();
|
|
67
53
|
_this.chart.on('interval:click', function (e) {
|
|
68
54
|
_this.props.toggleStatisticRecordsDialog(e.data.data, statItem);
|
|
69
55
|
});
|
|
70
|
-
var table_id = statItem.table_id,
|
|
71
|
-
summary_type = statItem.summary_type,
|
|
72
|
-
y_axis_column_key = statItem.y_axis_column_key,
|
|
73
|
-
y_axis_summary_type = statItem.y_axis_summary_type,
|
|
74
|
-
summary_method = statItem.summary_method,
|
|
75
|
-
y_axis_summary_method = statItem.y_axis_summary_method,
|
|
76
|
-
column_groupby_column_key = statItem.column_groupby_column_key,
|
|
77
|
-
column_groupby_multiple_numeric_column = statItem.column_groupby_multiple_numeric_column,
|
|
78
|
-
y_axis_use_stack = statItem.y_axis_use_stack,
|
|
79
|
-
y_axis_auto_range = statItem.y_axis_auto_range,
|
|
80
|
-
y_axis_min = statItem.y_axis_min,
|
|
81
|
-
y_axis_max = statItem.y_axis_max,
|
|
82
|
-
color_option = statItem.color_option;
|
|
83
|
-
var chartBarColor,
|
|
84
|
-
columnData = DEFAULT_NUMBER_FORMAT_OBJECT;
|
|
85
56
|
var isGroupBar = column_groupby_column_key || column_groupby_multiple_numeric_column;
|
|
57
|
+
var currentTheme = getCurrentTheme(colorThemeName);
|
|
58
|
+
var summaryColumnData = DEFAULT_NUMBER_FORMAT_OBJECT;
|
|
59
|
+
var summaryType = summary_type;
|
|
60
|
+
var summaryMethod = summary_method;
|
|
86
61
|
if (y_axis_summary_type === SUMMARY_TYPE.ADVANCED) {
|
|
87
62
|
var table = getTableById(table_id);
|
|
88
63
|
var summaryColumn = TableUtils.getTableColumnByKey(table, y_axis_column_key) || {};
|
|
89
|
-
|
|
64
|
+
summaryColumnData = summaryColumn.data || DEFAULT_NUMBER_FORMAT_OBJECT;
|
|
90
65
|
}
|
|
91
|
-
if (!
|
|
92
|
-
|
|
66
|
+
if (!summaryType && y_axis_summary_type) {
|
|
67
|
+
summaryType = y_axis_summary_type;
|
|
93
68
|
}
|
|
94
|
-
if (!
|
|
95
|
-
|
|
69
|
+
if (!summaryMethod && y_axis_summary_method) {
|
|
70
|
+
summaryMethod = y_axis_summary_method;
|
|
96
71
|
}
|
|
72
|
+
var chartBarColor = '#2a67d1';
|
|
97
73
|
if (isGroupBar) {
|
|
98
74
|
chartBarColor = 'group_name';
|
|
99
75
|
_this.chart.scale('group_name', {
|
|
@@ -101,8 +77,6 @@ var BarChart = /*#__PURE__*/function (_BaseChart) {
|
|
|
101
77
|
});
|
|
102
78
|
} else if (currentTheme && currentTheme.colors) {
|
|
103
79
|
chartBarColor = currentTheme.colors[0];
|
|
104
|
-
} else {
|
|
105
|
-
chartBarColor = '#2a67d1';
|
|
106
80
|
}
|
|
107
81
|
_this.chart.data(data, {
|
|
108
82
|
'name': {
|
|
@@ -111,45 +85,209 @@ var BarChart = /*#__PURE__*/function (_BaseChart) {
|
|
|
111
85
|
}
|
|
112
86
|
});
|
|
113
87
|
var width = _this.chart.coordinateBBox.width;
|
|
114
|
-
var chartData;
|
|
115
|
-
var themeColors =
|
|
116
|
-
|
|
117
|
-
|
|
88
|
+
var chartData = isGroupBar ? getChartGroups(data) : data;
|
|
89
|
+
var themeColors = _this.getThemeColors();
|
|
90
|
+
var ticks = _this.getTicks(chartData, width);
|
|
91
|
+
if (ticks.length > 0) {
|
|
92
|
+
_this.chart.scale('name', {
|
|
93
|
+
ticks: ticks
|
|
94
|
+
});
|
|
118
95
|
}
|
|
96
|
+
|
|
97
|
+
// set Coord type
|
|
98
|
+
_this.chart.coordinate('rect');
|
|
99
|
+
_this.handleAutoRange(data, summaryColumnData, summaryMethod);
|
|
119
100
|
if (isGroupBar) {
|
|
120
|
-
|
|
101
|
+
_this.drawBarGroup({
|
|
102
|
+
data: data,
|
|
103
|
+
themeColors: themeColors,
|
|
104
|
+
currentTheme: currentTheme,
|
|
105
|
+
summaryColumnData: summaryColumnData,
|
|
106
|
+
summaryType: summaryType,
|
|
107
|
+
summaryMethod: summaryMethod
|
|
108
|
+
});
|
|
121
109
|
} else {
|
|
122
|
-
|
|
110
|
+
_this.drawBar({
|
|
111
|
+
themeColors: themeColors,
|
|
112
|
+
chartBarColor: chartBarColor,
|
|
113
|
+
summaryType: summaryType,
|
|
114
|
+
summaryMethod: summaryMethod
|
|
115
|
+
});
|
|
123
116
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
117
|
+
_this.setTooltip();
|
|
118
|
+
_this.setAxis(themeColors);
|
|
119
|
+
_this.setLegend(themeColors);
|
|
120
|
+
_this.chart.interaction('active-region');
|
|
121
|
+
_this.chart.render();
|
|
122
|
+
_this.renderAxisLabel();
|
|
123
|
+
};
|
|
124
|
+
_this.initChartHandler = function () {
|
|
125
|
+
var _this$props2 = _this.props,
|
|
126
|
+
isPreview = _this$props2.isPreview,
|
|
127
|
+
statItem = _this$props2.statItem;
|
|
128
|
+
var display_data = statItem.display_data;
|
|
129
|
+
var config = {
|
|
130
|
+
container: _this.container,
|
|
131
|
+
autoFit: true,
|
|
132
|
+
appendPadding: [display_data ? 17 : 0, 0, 0, 0]
|
|
133
|
+
};
|
|
134
|
+
if (!isPreview) {
|
|
135
|
+
config.height = 400;
|
|
136
|
+
config.width = 700;
|
|
137
|
+
}
|
|
138
|
+
_this.chart = new Chart(config);
|
|
139
|
+
};
|
|
140
|
+
_this.drawBar = function (_ref) {
|
|
141
|
+
var themeColors = _ref.themeColors,
|
|
142
|
+
chartBarColor = _ref.chartBarColor,
|
|
143
|
+
summaryType = _ref.summaryType,
|
|
144
|
+
summaryMethod = _ref.summaryMethod;
|
|
145
|
+
var statItem = _this.props.statItem;
|
|
146
|
+
var color_option = statItem.color_option,
|
|
147
|
+
display_data = statItem.display_data;
|
|
148
|
+
var colorRules = color_option === TYPE_COLOR_USING.USE_RULES && statItem.y_axis_label_color_rules && getConvertedColorRules(statItem.y_axis_label_color_rules);
|
|
149
|
+
_this.chart.interval().label(display_data ? 'formatted_value' : false, {
|
|
150
|
+
style: {
|
|
151
|
+
fontSize: _this.getLabelFontSize(),
|
|
152
|
+
fill: themeColors.textColor
|
|
153
|
+
}
|
|
154
|
+
}).position('name*value').tooltip('name*formatted_value', function (name, value) {
|
|
155
|
+
return {
|
|
156
|
+
value: value,
|
|
157
|
+
title: summaryType === STATISTICS_COUNT_TYPE.COUNT ? intl.get(TITLE_AMOUNT) : intl.get(STATISTICS_COUNT_SHOW[summaryMethod]),
|
|
158
|
+
name: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name
|
|
159
|
+
};
|
|
160
|
+
}).state({
|
|
161
|
+
active: {
|
|
162
|
+
style: {
|
|
163
|
+
stroke: null
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}).style('value', function (value) {
|
|
167
|
+
var color = getLabelColor({
|
|
168
|
+
chart: statItem,
|
|
169
|
+
colorRules: colorRules,
|
|
170
|
+
value: value
|
|
171
|
+
});
|
|
172
|
+
return {
|
|
173
|
+
fill: color || chartBarColor
|
|
174
|
+
};
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
_this.drawBarGroup = function (_ref2) {
|
|
178
|
+
var data = _ref2.data,
|
|
179
|
+
themeColors = _ref2.themeColors,
|
|
180
|
+
summaryColumnData = _ref2.summaryColumnData,
|
|
181
|
+
summaryType = _ref2.summaryType,
|
|
182
|
+
summaryMethod = _ref2.summaryMethod,
|
|
183
|
+
currentTheme = _ref2.currentTheme;
|
|
184
|
+
var statItem = _this.props.statItem;
|
|
185
|
+
var chartType = statItem.type,
|
|
186
|
+
color_option = statItem.color_option,
|
|
187
|
+
display_data = statItem.display_data,
|
|
188
|
+
y_axis_use_stack = statItem.y_axis_use_stack,
|
|
189
|
+
display_each_block_data = statItem.display_each_block_data;
|
|
190
|
+
var labelCfg = {
|
|
191
|
+
style: {
|
|
192
|
+
fontSize: _this.getLabelFontSize(),
|
|
193
|
+
fill: themeColors.textColor
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
var displayData = display_data;
|
|
197
|
+
if (chartType == STAT_TYPE.BAR_STACK) {
|
|
198
|
+
displayData = display_each_block_data;
|
|
199
|
+
if (displayData) {
|
|
200
|
+
labelCfg.position = 'middle';
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// get the total value of each stack
|
|
204
|
+
var dv = new DataSet.DataView().source(data);
|
|
205
|
+
dv.transform({
|
|
206
|
+
type: 'aggregate',
|
|
207
|
+
fields: ['value'],
|
|
208
|
+
operations: ['sum'],
|
|
209
|
+
as: ['value_sum'],
|
|
210
|
+
groupBy: ['name']
|
|
130
211
|
});
|
|
212
|
+
if (display_data) {
|
|
213
|
+
dv.rows.forEach(function (item) {
|
|
214
|
+
_this.chart.annotation().text({
|
|
215
|
+
content: _this.getNumberDisplayString(item.value_sum, summaryColumnData, summaryMethod),
|
|
216
|
+
position: {
|
|
217
|
+
name: item.name,
|
|
218
|
+
value: item.value_sum
|
|
219
|
+
},
|
|
220
|
+
offsetY: -10,
|
|
221
|
+
offsetX: -5
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
}
|
|
131
225
|
}
|
|
226
|
+
var groupColorCallback = currentTheme && currentTheme.colors;
|
|
132
227
|
|
|
133
|
-
//
|
|
134
|
-
|
|
228
|
+
// when the 'Group by' column is a 'single-select' column,
|
|
229
|
+
// and the user chooses to use the colors from the column.
|
|
230
|
+
if (color_option === TYPE_COLOR_USING.USE_COLUMN_COLORS) {
|
|
231
|
+
var groupColorMapping = {};
|
|
232
|
+
data.forEach(function (item) {
|
|
233
|
+
if (!groupColorMapping[item.group_name]) {
|
|
234
|
+
groupColorMapping[item.group_name] = item.color;
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
groupColorCallback = function groupColorCallback(group_name) {
|
|
238
|
+
return groupColorMapping[group_name];
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
_this.chart.scale({
|
|
242
|
+
group_name: {
|
|
243
|
+
type: 'cat'
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
_this.chart.interval().label(displayData ? 'formatted_value' : false, labelCfg).position('name*value').color('group_name', groupColorCallback).tooltip('name*formatted_value*group_name*raw_name', function (name, value, group_name, raw_name) {
|
|
247
|
+
var nameContent = !group_name && typeof group_name !== 'number' ? intl.get(EMPTY_NAME) : group_name;
|
|
248
|
+
var titleContent = !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name;
|
|
249
|
+
return {
|
|
250
|
+
value: value,
|
|
251
|
+
title: titleContent,
|
|
252
|
+
name: nameContent
|
|
253
|
+
};
|
|
254
|
+
}).adjust([{
|
|
255
|
+
type: y_axis_use_stack ? 'stack' : 'dodge'
|
|
256
|
+
}]).state({
|
|
257
|
+
active: {
|
|
258
|
+
style: {
|
|
259
|
+
stroke: null
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
_this.handleAutoRange = function (data, summaryColumnData, summaryMethod) {
|
|
265
|
+
var _this$props$statItem = _this.props.statItem,
|
|
266
|
+
y_axis_auto_range = _this$props$statItem.y_axis_auto_range,
|
|
267
|
+
y_axis_min = _this$props$statItem.y_axis_min,
|
|
268
|
+
y_axis_max = _this$props$statItem.y_axis_max;
|
|
135
269
|
var valueScaleOptions = {
|
|
136
270
|
formatter: function formatter(value) {
|
|
137
|
-
return getNumberDisplayString(value,
|
|
271
|
+
return _this.getNumberDisplayString(value, summaryColumnData, summaryMethod);
|
|
138
272
|
}
|
|
139
273
|
};
|
|
274
|
+
|
|
275
|
+
// eslint-disable-next-line
|
|
140
276
|
if (y_axis_auto_range == undefined || y_axis_auto_range) {
|
|
141
|
-
valueScaleOptions = Object.assign(
|
|
277
|
+
valueScaleOptions = Object.assign(valueScaleOptions, {
|
|
142
278
|
nice: true
|
|
143
279
|
});
|
|
144
280
|
} else {
|
|
145
|
-
valueScaleOptions = Object.assign(
|
|
281
|
+
valueScaleOptions = Object.assign(valueScaleOptions, {
|
|
146
282
|
min: y_axis_min,
|
|
147
283
|
max: y_axis_max
|
|
148
284
|
});
|
|
285
|
+
|
|
149
286
|
// set the filter rule
|
|
150
287
|
_this.chart.filter('value', function (value) {
|
|
151
288
|
return value >= y_axis_min;
|
|
152
289
|
});
|
|
290
|
+
|
|
153
291
|
// filter the data
|
|
154
292
|
_this.chart.filterData(data);
|
|
155
293
|
}
|
|
@@ -160,133 +298,20 @@ var BarChart = /*#__PURE__*/function (_BaseChart) {
|
|
|
160
298
|
},
|
|
161
299
|
value: valueScaleOptions
|
|
162
300
|
});
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
style: {
|
|
166
|
-
fontSize: _this.getLabelFontSize(),
|
|
167
|
-
fill: themeColors.textColor
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
var displayData = display_data;
|
|
171
|
-
if (statItem.type == STAT_TYPE.BAR_STACK) {
|
|
172
|
-
var display_each_block_data = statItem.display_each_block_data;
|
|
173
|
-
displayData = display_each_block_data;
|
|
174
|
-
if (displayData) {
|
|
175
|
-
labelCfg.position = 'middle';
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// get the total value of each stack
|
|
179
|
-
var dv = new DataSet.DataView().source(data);
|
|
180
|
-
dv.transform({
|
|
181
|
-
type: 'aggregate',
|
|
182
|
-
fields: ['value'],
|
|
183
|
-
operations: ['sum'],
|
|
184
|
-
as: ['value_sum'],
|
|
185
|
-
groupBy: ['name']
|
|
186
|
-
});
|
|
187
|
-
if (display_data) {
|
|
188
|
-
dv.rows.forEach(function (item) {
|
|
189
|
-
_this.chart.annotation().text({
|
|
190
|
-
content: getNumberDisplayString(item.value_sum, columnData),
|
|
191
|
-
position: {
|
|
192
|
-
name: item.name,
|
|
193
|
-
value: item.value_sum
|
|
194
|
-
},
|
|
195
|
-
offsetY: -10,
|
|
196
|
-
offsetX: -5
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
var groupColorCallback = currentTheme && currentTheme.colors;
|
|
202
|
-
// when the 'Group by' column is a 'single-select' column,
|
|
203
|
-
// and the user chooses to use the colors from the column.
|
|
204
|
-
if (color_option === TYPE_COLOR_USING.USE_COLUMN_COLORS) {
|
|
205
|
-
var groupColorMapping = {};
|
|
206
|
-
data.forEach(function (item) {
|
|
207
|
-
if (!groupColorMapping[item.group_name]) {
|
|
208
|
-
groupColorMapping[item.group_name] = item.color;
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
groupColorCallback = function groupColorCallback(group_name) {
|
|
212
|
-
return groupColorMapping[group_name];
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
_this.chart.scale({
|
|
216
|
-
group_name: {
|
|
217
|
-
type: 'cat'
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
_this.chart.interval().label(displayData ? 'value' : false, labelCfg).position('name*value').color('group_name', groupColorCallback).tooltip('name*value*group_name*raw_name', function (name, value, group_name, raw_name) {
|
|
221
|
-
var nameContent = !group_name && typeof group_name !== 'number' ? intl.get(EMPTY_NAME) : group_name;
|
|
222
|
-
var titleContent = !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name;
|
|
223
|
-
return {
|
|
224
|
-
title: titleContent,
|
|
225
|
-
value: getNumberDisplayString(value, columnData),
|
|
226
|
-
name: nameContent
|
|
227
|
-
};
|
|
228
|
-
}).adjust([{
|
|
229
|
-
type: y_axis_use_stack ? 'stack' : 'dodge'
|
|
230
|
-
}]).state({
|
|
231
|
-
active: {
|
|
232
|
-
style: {
|
|
233
|
-
stroke: null
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
} else {
|
|
238
|
-
var colorRules = statItem.color_option === TYPE_COLOR_USING.USE_RULES && statItem.y_axis_label_color_rules && getConvertedColorRules(statItem.y_axis_label_color_rules);
|
|
239
|
-
_this.chart.interval().label(display_data ? 'value' : false, {
|
|
240
|
-
style: {
|
|
241
|
-
fontSize: _this.getLabelFontSize(),
|
|
242
|
-
fill: themeColors.textColor
|
|
243
|
-
}
|
|
244
|
-
}).position('name*value').tooltip('name*value', function (name, value) {
|
|
245
|
-
return {
|
|
246
|
-
title: summary_type === STATISTICS_COUNT_TYPE.COUNT ? intl.get(TITLE_AMOUNT) : intl.get(STATISTICS_COUNT_SHOW[summary_method]),
|
|
247
|
-
value: getNumberDisplayString(value, columnData),
|
|
248
|
-
name: !name && typeof name !== 'number' ? intl.get(EMPTY_NAME) : name
|
|
249
|
-
};
|
|
250
|
-
}).state({
|
|
251
|
-
active: {
|
|
252
|
-
style: {
|
|
253
|
-
stroke: null
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}).style('value', function (value) {
|
|
257
|
-
var color = getLabelColor({
|
|
258
|
-
chart: statItem,
|
|
259
|
-
colorRules: colorRules,
|
|
260
|
-
value: value
|
|
261
|
-
});
|
|
262
|
-
if (color) {
|
|
263
|
-
return {
|
|
264
|
-
fill: color
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
return {
|
|
268
|
-
fill: chartBarColor
|
|
269
|
-
};
|
|
270
|
-
});
|
|
271
|
-
}
|
|
301
|
+
};
|
|
302
|
+
_this.setTooltip = function () {
|
|
272
303
|
_this.chart.tooltip({
|
|
273
304
|
showTitle: true,
|
|
274
305
|
showMarkers: false,
|
|
275
306
|
containerTpl: '<div class="g2-tooltip"><div class="g2-tooltip-list"></div></div>',
|
|
276
307
|
itemTpl: '<div class="g2-tooltip-content"><div class="tooltip-name">{title}<div><div class="tooltip-item">{name}: {value}<div></div>',
|
|
277
308
|
domStyles: {
|
|
278
|
-
'g2-tooltip':
|
|
279
|
-
|
|
280
|
-
backgroundColor: '#fff',
|
|
281
|
-
padding: '10px'
|
|
282
|
-
},
|
|
283
|
-
'tooltip-item': {
|
|
284
|
-
marginTop: '5px'
|
|
285
|
-
}
|
|
309
|
+
'g2-tooltip': _this.getDefaultChartStyleByKey('g2-tooltip'),
|
|
310
|
+
'tooltip-item': _this.getDefaultChartStyleByKey('tooltip-item')
|
|
286
311
|
}
|
|
287
312
|
});
|
|
288
|
-
|
|
289
|
-
|
|
313
|
+
};
|
|
314
|
+
_this.setAxis = function (themeColors) {
|
|
290
315
|
_this.chart.axis('name', {
|
|
291
316
|
line: {
|
|
292
317
|
style: themeColors.gridColor
|
|
@@ -296,16 +321,7 @@ var BarChart = /*#__PURE__*/function (_BaseChart) {
|
|
|
296
321
|
style: {
|
|
297
322
|
fill: themeColors.textColor
|
|
298
323
|
},
|
|
299
|
-
formatter:
|
|
300
|
-
var label = name;
|
|
301
|
-
if (name.length > 10) {
|
|
302
|
-
label = "".concat(name.slice(0, 10), "...");
|
|
303
|
-
}
|
|
304
|
-
if (name === '' || name === 'undefined') {
|
|
305
|
-
label = intl.get(EMPTY_NAME);
|
|
306
|
-
}
|
|
307
|
-
return label;
|
|
308
|
-
}
|
|
324
|
+
formatter: _this.labelFormatter
|
|
309
325
|
}
|
|
310
326
|
});
|
|
311
327
|
_this.chart.axis('value', {
|
|
@@ -322,6 +338,8 @@ var BarChart = /*#__PURE__*/function (_BaseChart) {
|
|
|
322
338
|
}
|
|
323
339
|
}
|
|
324
340
|
});
|
|
341
|
+
};
|
|
342
|
+
_this.setLegend = function (themeColors) {
|
|
325
343
|
var legendPosition = 'bottom';
|
|
326
344
|
_this.chart.legend('group_name', {
|
|
327
345
|
position: legendPosition,
|
|
@@ -348,23 +366,16 @@ var BarChart = /*#__PURE__*/function (_BaseChart) {
|
|
|
348
366
|
}
|
|
349
367
|
}
|
|
350
368
|
});
|
|
351
|
-
_this.chart.interaction('active-region');
|
|
352
|
-
_this.chart.render();
|
|
353
|
-
_this.renderAxisLabel();
|
|
354
369
|
};
|
|
355
370
|
_this.renderAxisLabel = function (newStatItem) {
|
|
356
|
-
var _this$
|
|
357
|
-
getTableById = _this$
|
|
358
|
-
statItem = _this$
|
|
371
|
+
var _this$props3 = _this.props,
|
|
372
|
+
getTableById = _this$props3.getTableById,
|
|
373
|
+
statItem = _this$props3.statItem;
|
|
359
374
|
if (newStatItem && newStatItem._id !== statItem._id) {
|
|
360
375
|
return;
|
|
361
376
|
}
|
|
362
377
|
if (!_this.chart) return;
|
|
363
378
|
statItem = newStatItem || statItem;
|
|
364
|
-
var _this$props3 = _this.props,
|
|
365
|
-
isEnlarge = _this$props3.isEnlarge,
|
|
366
|
-
isPreview = _this$props3.isPreview,
|
|
367
|
-
theme = _this$props3.theme;
|
|
368
379
|
var _statItem = statItem,
|
|
369
380
|
type = _statItem.type,
|
|
370
381
|
table_id = _statItem.table_id,
|
|
@@ -378,10 +389,7 @@ var BarChart = /*#__PURE__*/function (_BaseChart) {
|
|
|
378
389
|
title_name = _statItem.title_name;
|
|
379
390
|
var table = getTableById(table_id);
|
|
380
391
|
var autoPadding = _this.chart.autoPadding;
|
|
381
|
-
var textColor =
|
|
382
|
-
if (theme === 'dark' && !isEnlarge && isPreview) {
|
|
383
|
-
textColor = '#ffffff';
|
|
384
|
-
}
|
|
392
|
+
var textColor = _this.getAxisLabelColor();
|
|
385
393
|
var xAxisID = "chart-x-axis-label_".concat(statItem._id);
|
|
386
394
|
var chartContainer = _this.chart.getCanvas().get('container');
|
|
387
395
|
var xLabel = chartContainer.querySelector("#".concat(xAxisID));
|
|
@@ -438,11 +446,6 @@ var BarChart = /*#__PURE__*/function (_BaseChart) {
|
|
|
438
446
|
_this.chart.destroy();
|
|
439
447
|
_this.chart = null;
|
|
440
448
|
};
|
|
441
|
-
_this.getLabelFontSize = function () {
|
|
442
|
-
var statItem = _this.props.statItem;
|
|
443
|
-
var label_font_size = statItem.label_font_size;
|
|
444
|
-
return getLabelFontSize(label_font_size);
|
|
445
|
-
};
|
|
446
449
|
_this.state = {
|
|
447
450
|
isCalculatingData: true,
|
|
448
451
|
showResultDescription: true
|
|
@@ -547,13 +550,9 @@ var BarChart = /*#__PURE__*/function (_BaseChart) {
|
|
|
547
550
|
showResultDescription = _this$state.showResultDescription;
|
|
548
551
|
var show_y_axis_label = statItem.show_y_axis_label,
|
|
549
552
|
show_x_axis_label = statItem.show_x_axis_label;
|
|
550
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, isCalculatingData && /*#__PURE__*/React.createElement("div", {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
className: 'statistic-chart-text'
|
|
554
|
-
}, intl.get(NO_STATISTIC_RESULTS)), /*#__PURE__*/React.createElement("div", {
|
|
555
|
-
ref: function ref(_ref) {
|
|
556
|
-
return _this4.container = _ref;
|
|
553
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, isCalculatingData && this.renderLoading(), showResultDescription && this.renderEmpty(), /*#__PURE__*/React.createElement("div", {
|
|
554
|
+
ref: function ref(_ref3) {
|
|
555
|
+
return _this4.container = _ref3;
|
|
557
556
|
},
|
|
558
557
|
style: {
|
|
559
558
|
padding: show_y_axis_label || show_x_axis_label ? 30 : 20
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
2
|
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
3
3
|
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
4
|
-
import { Component } from 'react';
|
|
4
|
+
import React, { Component } from 'react';
|
|
5
|
+
import intl from 'react-intl-universal';
|
|
5
6
|
import { getNumberDisplayString } from 'dtable-store';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
7
|
+
import { Loading } from '../components';
|
|
8
|
+
import { getLabelFontSize, isStatItemEqual, shouldCalculateStatItem } from '../utils/common-utils';
|
|
9
|
+
import { getChartDisplayLabels } from '../utils/basic-chart-utils';
|
|
10
|
+
import { EMPTY_NAME, NO_STATISTIC_RESULTS, STAT_ITEM_THEME_COLORS, SUMMARY_METHOD_MAP, THEME_NAME_MAP } from '../constants';
|
|
11
|
+
var CHART_STYLE_CONFIG = {
|
|
12
|
+
'g2-tooltip': {
|
|
13
|
+
borderRadius: '2px',
|
|
14
|
+
backgroundColor: '#fff',
|
|
15
|
+
padding: '10px'
|
|
16
|
+
},
|
|
17
|
+
'tooltip-item': {
|
|
18
|
+
marginTop: '5px'
|
|
19
|
+
}
|
|
20
|
+
};
|
|
8
21
|
var BaseChart = /*#__PURE__*/function (_Component) {
|
|
9
22
|
_inherits(BaseChart, _Component);
|
|
10
23
|
var _super = _createSuper(BaseChart);
|
|
@@ -16,8 +29,8 @@ var BaseChart = /*#__PURE__*/function (_Component) {
|
|
|
16
29
|
}
|
|
17
30
|
_this = _super.call.apply(_super, [this].concat(args));
|
|
18
31
|
_this.needRefresh = function (preProps, nextProps) {
|
|
19
|
-
var
|
|
20
|
-
return
|
|
32
|
+
var dtableChangedTime = nextProps.dtableChangedTime;
|
|
33
|
+
return dtableChangedTime !== preProps.dtableChangedTime;
|
|
21
34
|
};
|
|
22
35
|
_this.canUpdate = function (preProps, nextProps) {
|
|
23
36
|
var statItem = preProps.statItem,
|
|
@@ -31,12 +44,71 @@ var BaseChart = /*#__PURE__*/function (_Component) {
|
|
|
31
44
|
var nextStatItem = nextProps.statItem;
|
|
32
45
|
return shouldCalculateStatItem(statItem, nextStatItem) || _this.needRefresh(preProps, nextProps);
|
|
33
46
|
};
|
|
34
|
-
_this.
|
|
35
|
-
|
|
47
|
+
_this.getTicks = function (data, width) {
|
|
48
|
+
var labelCount = data.length;
|
|
49
|
+
if (Math.floor(width / labelCount) > 20) {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
return getChartDisplayLabels(width, 20, data);
|
|
53
|
+
};
|
|
54
|
+
_this.getLabelCount = function (ticks, data) {
|
|
55
|
+
var ticksLen = ticks.length;
|
|
56
|
+
return ticksLen > 0 ? ticksLen : data.length;
|
|
57
|
+
};
|
|
58
|
+
_this.getThemeColors = function () {
|
|
59
|
+
var _this$props = _this.props,
|
|
60
|
+
isPreview = _this$props.isPreview,
|
|
61
|
+
isEnlarge = _this$props.isEnlarge,
|
|
62
|
+
theme = _this$props.theme;
|
|
63
|
+
if (isEnlarge || !isPreview) {
|
|
64
|
+
return STAT_ITEM_THEME_COLORS.light;
|
|
65
|
+
}
|
|
66
|
+
return theme === THEME_NAME_MAP.DARK ? STAT_ITEM_THEME_COLORS[THEME_NAME_MAP.DARK] : STAT_ITEM_THEME_COLORS[THEME_NAME_MAP.LIGHT];
|
|
67
|
+
};
|
|
68
|
+
_this.getAxisLabelColor = function (textColor) {
|
|
69
|
+
var _this$props2 = _this.props,
|
|
70
|
+
isPreview = _this$props2.isPreview,
|
|
71
|
+
isEnlarge = _this$props2.isEnlarge,
|
|
72
|
+
theme = _this$props2.theme;
|
|
73
|
+
if (theme === THEME_NAME_MAP.DARK && !isEnlarge && isPreview) {
|
|
74
|
+
return '#ffffff';
|
|
75
|
+
}
|
|
76
|
+
return textColor || '#999999';
|
|
77
|
+
};
|
|
78
|
+
_this.getDefaultChartStyleByKey = function (key) {
|
|
79
|
+
return CHART_STYLE_CONFIG[key] || {};
|
|
80
|
+
};
|
|
81
|
+
_this.labelFormatter = function (name) {
|
|
82
|
+
var label = name;
|
|
83
|
+
if (name.length > 10) {
|
|
84
|
+
label = "".concat(name.slice(0, 10), "...");
|
|
85
|
+
}
|
|
86
|
+
if (name === '' || name === 'undefined') {
|
|
87
|
+
label = intl.get(EMPTY_NAME);
|
|
88
|
+
}
|
|
89
|
+
return label;
|
|
90
|
+
};
|
|
91
|
+
_this.getLabelFontSize = function () {
|
|
92
|
+
var statItem = _this.props.statItem;
|
|
93
|
+
var label_font_size = statItem.label_font_size;
|
|
94
|
+
return getLabelFontSize(label_font_size);
|
|
95
|
+
};
|
|
96
|
+
_this.getNumberDisplayString = function (value, columnData, summaryMethod) {
|
|
97
|
+
if (summaryMethod === SUMMARY_METHOD_MAP.Distinct_values) {
|
|
36
98
|
return value;
|
|
37
99
|
}
|
|
38
100
|
return getNumberDisplayString(value, columnData);
|
|
39
101
|
};
|
|
102
|
+
_this.renderLoading = function () {
|
|
103
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
104
|
+
className: 'statistic-chart-loading-container'
|
|
105
|
+
}, /*#__PURE__*/React.createElement(Loading, null));
|
|
106
|
+
};
|
|
107
|
+
_this.renderEmpty = function () {
|
|
108
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
109
|
+
className: 'statistic-chart-text'
|
|
110
|
+
}, intl.get(NO_STATISTIC_RESULTS));
|
|
111
|
+
};
|
|
40
112
|
return _this;
|
|
41
113
|
}
|
|
42
114
|
return BaseChart;
|