dtable-statistic 4.1.2 → 4.1.4
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 +58 -0
- package/es/assets/icons/move-to.svg +20 -0
- package/es/calculator/map-calculator.js +23 -17
- package/es/calculator/workers/basic-chart-calculator-worker.js +7 -3
- package/es/calculator/world-map-calculator.js +5 -1
- package/es/components/dialog/chart-addition-edit-dialog.js +1 -0
- package/es/components/dialog/enlarged-chart-dialog.js +1 -0
- package/es/components/dropdown-menu/statistic-dropdown-menu.js +79 -3
- package/es/constants/index.js +1 -0
- package/es/constants/map.js +7 -0
- package/es/constants/regions.js +2106 -0
- package/es/dashboard.js +31 -1
- package/es/desktop-dashboard.js +23 -10
- package/es/locale/lang/en.js +2 -1
- package/es/locale/lang/zh_CN.js +2 -1
- package/es/mobile-dashboard.js +3 -1
- package/es/model/generic-model.js +5 -0
- package/es/model/map.js +5 -2
- package/es/service/dashboard-service.js +39 -0
- package/es/service/map-json.js +154 -0
- package/es/stat-editor/index.js +1 -0
- package/es/stat-editor/stat-settings/advance-chart-settings/map-settings.js +10 -35
- package/es/stat-editor/stat-settings/map/map-level.js +76 -0
- package/es/stat-editor/stat-settings/map/map-province-city.js +144 -0
- package/es/stat-list/chart-preview.js +8 -1
- package/es/stat-list/index.js +4 -0
- package/es/stat-view/index.js +1 -0
- package/es/stat-view/map.js +69 -42
- package/es/stat-view/world-map.js +13 -16
- package/es/utils/map.js +108 -0
- package/package.json +3 -3
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
4
|
+
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
|
+
import React, { Component, Fragment } from 'react';
|
|
6
|
+
import { DTableSelect } from '../../../components';
|
|
7
|
+
import { MAP_LEVEL } from '../../../constants/map';
|
|
8
|
+
import { regions } from '../../../constants/regions';
|
|
9
|
+
import { fixGeoGranularity } from '../../../utils/map';
|
|
10
|
+
var MapProvinceCitySettings = /*#__PURE__*/function (_Component) {
|
|
11
|
+
_inherits(MapProvinceCitySettings, _Component);
|
|
12
|
+
var _super = _createSuper(MapProvinceCitySettings);
|
|
13
|
+
function MapProvinceCitySettings(props) {
|
|
14
|
+
var _this;
|
|
15
|
+
_classCallCheck(this, MapProvinceCitySettings);
|
|
16
|
+
_this = _super.call(this, props);
|
|
17
|
+
_this.isProvinceWithCities = function (province) {
|
|
18
|
+
var provinceWithCities = regions.find(function (provinceWithCities) {
|
|
19
|
+
return provinceWithCities.name === province;
|
|
20
|
+
});
|
|
21
|
+
return provinceWithCities && provinceWithCities.cities.length > 0;
|
|
22
|
+
};
|
|
23
|
+
_this.createProvinceOptions = function () {
|
|
24
|
+
return regions.map(function (provinceWithCities) {
|
|
25
|
+
var name = provinceWithCities.name;
|
|
26
|
+
return {
|
|
27
|
+
label: /*#__PURE__*/React.createElement("span", {
|
|
28
|
+
className: "select-option-name"
|
|
29
|
+
}, name),
|
|
30
|
+
value: name
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
_this.createProvinceCitiesOptions = function (province) {
|
|
35
|
+
var provinceWithCities = regions.find(function (provinceWithCities) {
|
|
36
|
+
return provinceWithCities.name === province;
|
|
37
|
+
});
|
|
38
|
+
if (!provinceWithCities || provinceWithCities.cities.length === 0) return [];
|
|
39
|
+
return provinceWithCities.cities.map(function (city) {
|
|
40
|
+
var name = city.name;
|
|
41
|
+
return {
|
|
42
|
+
label: /*#__PURE__*/React.createElement("span", {
|
|
43
|
+
className: "select-option-name"
|
|
44
|
+
}, name),
|
|
45
|
+
value: name
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
_this.getProvinceCitiesOptions = function (province) {
|
|
50
|
+
if (_this.provinceCitiesOptionsMap[province]) {
|
|
51
|
+
return _this.provinceCitiesOptionsMap[province];
|
|
52
|
+
}
|
|
53
|
+
var citiesOptions = _this.createProvinceCitiesOptions(province);
|
|
54
|
+
_this.provinceCitiesOptionsMap[province] = citiesOptions;
|
|
55
|
+
return citiesOptions;
|
|
56
|
+
};
|
|
57
|
+
_this.getSelectedProvinceOption = function () {
|
|
58
|
+
var map_location = _this.props.statItem.map_location;
|
|
59
|
+
var province = map_location && map_location.province;
|
|
60
|
+
if (!province) return null;
|
|
61
|
+
return _this.provinceOptions.find(function (option) {
|
|
62
|
+
return option.value === province;
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
_this.getSelectedCity = function (citiesOptions) {
|
|
66
|
+
var map_location = _this.props.statItem.map_location;
|
|
67
|
+
var city = map_location && map_location.city;
|
|
68
|
+
if (!city) return null;
|
|
69
|
+
return citiesOptions.find(function (option) {
|
|
70
|
+
return option.value === city;
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
_this.onSelectProvince = function (option) {
|
|
74
|
+
var statItem = _this.props.statItem;
|
|
75
|
+
var map_level = statItem.map_level,
|
|
76
|
+
map_location = statItem.map_location;
|
|
77
|
+
var newMapLocation = {
|
|
78
|
+
province: option.value
|
|
79
|
+
};
|
|
80
|
+
if (map_location && newMapLocation.province === map_location.province) return;
|
|
81
|
+
var updated = {
|
|
82
|
+
map_location: newMapLocation,
|
|
83
|
+
geolocation_granularity: fixGeoGranularity({
|
|
84
|
+
mapLevel: map_level,
|
|
85
|
+
mapLocation: newMapLocation
|
|
86
|
+
})
|
|
87
|
+
};
|
|
88
|
+
_this.props.updateStatItem(Object.assign({}, statItem, updated));
|
|
89
|
+
};
|
|
90
|
+
_this.onSelectCity = function (option) {
|
|
91
|
+
var statItem = _this.props.statItem;
|
|
92
|
+
var map_level = statItem.map_level,
|
|
93
|
+
map_location = statItem.map_location;
|
|
94
|
+
var newMapLocation = Object.assign({}, map_location, {
|
|
95
|
+
city: option.value
|
|
96
|
+
});
|
|
97
|
+
if (map_location && newMapLocation.city === map_location.city) return;
|
|
98
|
+
var updated = {
|
|
99
|
+
map_location: newMapLocation,
|
|
100
|
+
geolocation_granularity: fixGeoGranularity({
|
|
101
|
+
mapLevel: map_level,
|
|
102
|
+
mapLocation: newMapLocation
|
|
103
|
+
})
|
|
104
|
+
};
|
|
105
|
+
_this.props.updateStatItem(Object.assign({}, statItem, updated));
|
|
106
|
+
};
|
|
107
|
+
_this.renderCitySelector = function () {
|
|
108
|
+
var map_location = _this.props.statItem.map_location;
|
|
109
|
+
var province = map_location && map_location.province;
|
|
110
|
+
var citiesOptions = _this.getProvinceCitiesOptions(province);
|
|
111
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
112
|
+
className: "statistic-chart-parameter-item"
|
|
113
|
+
}, /*#__PURE__*/React.createElement(DTableSelect, {
|
|
114
|
+
value: _this.getSelectedCity(citiesOptions),
|
|
115
|
+
options: citiesOptions,
|
|
116
|
+
onChange: _this.onSelectCity,
|
|
117
|
+
placeholder: "\u8BF7\u9009\u62E9\u57CE\u5E02"
|
|
118
|
+
}));
|
|
119
|
+
};
|
|
120
|
+
_this.provinceOptions = _this.createProvinceOptions();
|
|
121
|
+
_this.provinceCitiesOptionsMap = {};
|
|
122
|
+
return _this;
|
|
123
|
+
}
|
|
124
|
+
_createClass(MapProvinceCitySettings, [{
|
|
125
|
+
key: "render",
|
|
126
|
+
value: function render() {
|
|
127
|
+
var map_level = this.props.statItem.map_level;
|
|
128
|
+
if (map_level !== MAP_LEVEL.PROVINCE && map_level !== MAP_LEVEL.CITY) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
var isCity = map_level === MAP_LEVEL.CITY;
|
|
132
|
+
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
133
|
+
className: "statistic-chart-parameter-item"
|
|
134
|
+
}, /*#__PURE__*/React.createElement("label", null, isCity ? '城市' : '省份'), /*#__PURE__*/React.createElement(DTableSelect, {
|
|
135
|
+
value: this.getSelectedProvinceOption(),
|
|
136
|
+
options: this.provinceOptions,
|
|
137
|
+
onChange: this.onSelectProvince,
|
|
138
|
+
placeholder: "\u8BF7\u9009\u62E9\u7701\u4EFD"
|
|
139
|
+
})), isCity && this.renderCitySelector());
|
|
140
|
+
}
|
|
141
|
+
}]);
|
|
142
|
+
return MapProvinceCitySettings;
|
|
143
|
+
}(Component);
|
|
144
|
+
export default MapProvinceCitySettings;
|
|
@@ -87,9 +87,14 @@ var ChartPreview = /*#__PURE__*/function (_Component) {
|
|
|
87
87
|
chartCalculator: chartCalculator,
|
|
88
88
|
eventBus: eventBus,
|
|
89
89
|
getTableById: _this.props.getTableById,
|
|
90
|
+
queryMapJson: _this.props.queryMapJson,
|
|
90
91
|
toggleStatisticRecordsDialog: _this.props.toggleStatisticRecordsDialog
|
|
91
92
|
});
|
|
92
93
|
};
|
|
94
|
+
_this.moveChartToView = function (viewId) {
|
|
95
|
+
var statItem = _this.props.statItem;
|
|
96
|
+
_this.props.moveChartToView(statItem._id, viewId);
|
|
97
|
+
};
|
|
93
98
|
return _this;
|
|
94
99
|
}
|
|
95
100
|
_createClass(ChartPreview, [{
|
|
@@ -117,12 +122,14 @@ var ChartPreview = /*#__PURE__*/function (_Component) {
|
|
|
117
122
|
})), /*#__PURE__*/React.createElement(StatisticDropdownMenu, {
|
|
118
123
|
isTableReadOnly: isTableReadOnly,
|
|
119
124
|
chartType: type,
|
|
125
|
+
getOtherStatistics: this.props.getOtherStatistics,
|
|
120
126
|
onExportChart: function onExportChart() {
|
|
121
127
|
return _this2.onExportChart(statItem);
|
|
122
128
|
},
|
|
123
|
-
deleteStatItem: this.props.deleteChart.bind(this, statId),
|
|
124
129
|
editStatItem: this.props.onToggleEditChart.bind(this, statId),
|
|
125
130
|
copyStatItem: this.props.copyChart.bind(this, statId),
|
|
131
|
+
moveChartToView: this.moveChartToView,
|
|
132
|
+
deleteStatItem: this.props.deleteChart.bind(this, statId),
|
|
126
133
|
onNewTableDialogToggle: this.onNewTableDialogToggle,
|
|
127
134
|
onUpdateTableDialogToggle: this.onUpdateTableDialogToggle
|
|
128
135
|
}))), /*#__PURE__*/React.createElement("div", {
|
package/es/stat-list/index.js
CHANGED
|
@@ -234,9 +234,12 @@ var StatList = /*#__PURE__*/function (_Component) {
|
|
|
234
234
|
statItem: statItem,
|
|
235
235
|
chartCalculator: chartCalculator,
|
|
236
236
|
eventBus: eventBus,
|
|
237
|
+
getOtherStatistics: _this2.props.getOtherStatistics,
|
|
237
238
|
getTableById: _this2.props.getTableById,
|
|
238
239
|
getTables: _this2.props.getTables,
|
|
240
|
+
queryMapJson: _this2.props.queryMapJson,
|
|
239
241
|
copyChart: _this2.props.copyChart,
|
|
242
|
+
moveChartToView: _this2.props.moveChartToView,
|
|
240
243
|
deleteChart: _this2.props.deleteChart,
|
|
241
244
|
enlargeChart: function enlargeChart() {
|
|
242
245
|
return _this2.enlargeChart(index);
|
|
@@ -260,6 +263,7 @@ var StatList = /*#__PURE__*/function (_Component) {
|
|
|
260
263
|
eventBus: eventBus,
|
|
261
264
|
chartCalculator: chartCalculator,
|
|
262
265
|
getTableById: this.props.getTableById,
|
|
266
|
+
queryMapJson: this.props.queryMapJson,
|
|
263
267
|
onEnlargeToggle: this.closeEnlargedChart,
|
|
264
268
|
onToggleShowEnlarged: this.closeEnlargedChart,
|
|
265
269
|
toggleStatisticRecordsDialog: this.props.toggleStatisticRecordsDialog
|
package/es/stat-view/index.js
CHANGED
|
@@ -67,6 +67,7 @@ var StatView = /*#__PURE__*/function (_React$Component) {
|
|
|
67
67
|
chartCalculator: chartCalculator,
|
|
68
68
|
eventBus: eventBus,
|
|
69
69
|
getTableById: getTableById,
|
|
70
|
+
queryMapJson: this.props.queryMapJson,
|
|
70
71
|
toggleStatisticRecordsDialog: toggleStatisticRecordsDialog,
|
|
71
72
|
ref: function ref(_ref) {
|
|
72
73
|
_this2.chartView = _ref;
|
package/es/stat-view/map.js
CHANGED
|
@@ -9,8 +9,9 @@ import { TableUtils } from 'dtable-store';
|
|
|
9
9
|
import BaseChart from './base-chart';
|
|
10
10
|
import { Chart } from '../custom-g2';
|
|
11
11
|
import { COLOR_OPTIONS, DEFAULT_NUMBER_FORMAT_OBJECT, SUMMARY_TYPE } from '../constants';
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
import { MAP_LEVEL } from '../constants/map';
|
|
13
|
+
import { shallowEqual } from '../utils/common-utils';
|
|
14
|
+
import { getRegionScaleOffsets } from '../utils/map';
|
|
14
15
|
var Map = /*#__PURE__*/function (_BaseChart) {
|
|
15
16
|
_inherits(Map, _BaseChart);
|
|
16
17
|
var _super = _createSuper(Map);
|
|
@@ -18,6 +19,36 @@ var Map = /*#__PURE__*/function (_BaseChart) {
|
|
|
18
19
|
var _this;
|
|
19
20
|
_classCallCheck(this, Map);
|
|
20
21
|
_this = _super.call(this, props);
|
|
22
|
+
_this.hasMapChanged = function (preStatItem, statItem) {
|
|
23
|
+
var preMapLevel = preStatItem.map_level,
|
|
24
|
+
prevMapLocation = preStatItem.map_location;
|
|
25
|
+
var map_level = statItem.map_level,
|
|
26
|
+
map_location = statItem.map_location;
|
|
27
|
+
return map_level !== preMapLevel || !shallowEqual(map_location, prevMapLocation);
|
|
28
|
+
};
|
|
29
|
+
_this.reCalculateChart = function (statItem) {
|
|
30
|
+
_this.rerenderChart();
|
|
31
|
+
_this.props.chartCalculator.calculate(statItem).then(function (statData) {
|
|
32
|
+
_this.calculateData = statData;
|
|
33
|
+
_this.setState({
|
|
34
|
+
isCalculatingData: false
|
|
35
|
+
});
|
|
36
|
+
_this.updateStatisticData(_this.fixData(statData));
|
|
37
|
+
if (_this.props.isPreview) {
|
|
38
|
+
var canvasSize = _this.getCanvasSize();
|
|
39
|
+
_this.chart.changeSize(canvasSize.w, canvasSize.h);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
_this.rerenderChart = function () {
|
|
44
|
+
if (!_this.chart) return;
|
|
45
|
+
_this.chart.destroy();
|
|
46
|
+
_this.initStatisticContext(_this.geoData);
|
|
47
|
+
};
|
|
48
|
+
_this.getMapLevel = function (statItem) {
|
|
49
|
+
var map_level = statItem.map_level;
|
|
50
|
+
return map_level || MAP_LEVEL.COUNTRY;
|
|
51
|
+
};
|
|
21
52
|
_this.fixData = function (statisticData) {
|
|
22
53
|
if (!statisticData) return [];
|
|
23
54
|
var statisticNewData = [];
|
|
@@ -113,16 +144,14 @@ var Map = /*#__PURE__*/function (_BaseChart) {
|
|
|
113
144
|
return _this.getNumberDisplayString(value, columnData, summary_method);
|
|
114
145
|
}
|
|
115
146
|
},
|
|
116
|
-
|
|
117
|
-
style: {
|
|
118
|
-
'opacity': 0
|
|
119
|
-
}
|
|
120
|
-
}
|
|
147
|
+
slidable: false
|
|
121
148
|
});
|
|
122
149
|
_this.statisticView.interaction('element-active');
|
|
123
150
|
_this.statisticView.render();
|
|
124
151
|
};
|
|
125
152
|
_this.updateStatisticData = function (data) {
|
|
153
|
+
_this.rerenderChart();
|
|
154
|
+
|
|
126
155
|
// re-render statistic data view;
|
|
127
156
|
if (_this.statisticView) {
|
|
128
157
|
_this.statisticView.destroy();
|
|
@@ -165,6 +194,9 @@ var Map = /*#__PURE__*/function (_BaseChart) {
|
|
|
165
194
|
}
|
|
166
195
|
_this.statisticView = _this.chart.createView();
|
|
167
196
|
_this.statisticView.data(userDv.rows);
|
|
197
|
+
_this.chart.theme({
|
|
198
|
+
defaultColor: statItem.bubble_color || '#2a67d1'
|
|
199
|
+
});
|
|
168
200
|
_this.statisticView.point().position('longitude*latitude').size('value', function (value) {
|
|
169
201
|
var percent = value / data.sum;
|
|
170
202
|
var size = percent * 100;
|
|
@@ -209,23 +241,25 @@ var Map = /*#__PURE__*/function (_BaseChart) {
|
|
|
209
241
|
return _this.getNumberDisplayString(value, columnData, summary_method);
|
|
210
242
|
}
|
|
211
243
|
},
|
|
212
|
-
|
|
213
|
-
style: {
|
|
214
|
-
'opacity': 0
|
|
215
|
-
}
|
|
216
|
-
}
|
|
244
|
+
slidable: false
|
|
217
245
|
});
|
|
218
246
|
_this.statisticView.interaction('element-active');
|
|
219
247
|
_this.statisticView.render();
|
|
220
248
|
};
|
|
221
249
|
_this.getCanvasSize = function () {
|
|
250
|
+
var statItem = _this.props.statItem;
|
|
251
|
+
var map_level = statItem.map_level,
|
|
252
|
+
map_location = statItem.map_location;
|
|
222
253
|
var maxWidth = _this.container.clientWidth;
|
|
223
254
|
var maxHeight = _this.container.clientHeight;
|
|
255
|
+
var _getRegionScaleOffset = getRegionScaleOffsets(map_level, map_location),
|
|
256
|
+
scale_w = _getRegionScaleOffset.scale_w,
|
|
257
|
+
scale_h = _getRegionScaleOffset.scale_h;
|
|
224
258
|
var h = maxHeight;
|
|
225
|
-
var w = h * (
|
|
259
|
+
var w = h * (scale_w / scale_h);
|
|
226
260
|
if (w > maxWidth) {
|
|
227
261
|
w = maxWidth;
|
|
228
|
-
h = w * (
|
|
262
|
+
h = w * (scale_h / scale_w);
|
|
229
263
|
}
|
|
230
264
|
return {
|
|
231
265
|
w: w,
|
|
@@ -292,10 +326,6 @@ var Map = /*#__PURE__*/function (_BaseChart) {
|
|
|
292
326
|
_this.dataSet.createView('statisticViewModel');
|
|
293
327
|
mapView.render();
|
|
294
328
|
};
|
|
295
|
-
_this.getGeoLocationData = function () {
|
|
296
|
-
var mediaUrl = window.dtable.mediaUrl;
|
|
297
|
-
return fetch("".concat(mediaUrl, "dtable-statistic/geolocation/china.json")).catch(function (err) {});
|
|
298
|
-
};
|
|
299
329
|
_this.state = {
|
|
300
330
|
isDataLoaded: false,
|
|
301
331
|
isCalculatingData: true
|
|
@@ -310,15 +340,18 @@ var Map = /*#__PURE__*/function (_BaseChart) {
|
|
|
310
340
|
var _this$props3 = this.props,
|
|
311
341
|
statItem = _this$props3.statItem,
|
|
312
342
|
chartCalculator = _this$props3.chartCalculator;
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
343
|
+
var map_location = statItem.map_location;
|
|
344
|
+
var mapLevel = this.getMapLevel(statItem);
|
|
345
|
+
this.props.queryMapJson({
|
|
346
|
+
map_level: mapLevel,
|
|
347
|
+
map_location: map_location
|
|
348
|
+
}, function (mapJson) {
|
|
316
349
|
_this2.setState({
|
|
317
350
|
isDataLoaded: true
|
|
318
351
|
}, function () {
|
|
319
|
-
if (!
|
|
320
|
-
_this2.geoData =
|
|
321
|
-
_this2.initStatisticContext(
|
|
352
|
+
if (!mapJson) return;
|
|
353
|
+
_this2.geoData = mapJson;
|
|
354
|
+
_this2.initStatisticContext(mapJson);
|
|
322
355
|
if (_this2.container) {
|
|
323
356
|
chartCalculator.calculate(statItem).then(function (data) {
|
|
324
357
|
_this2.calculateData = data;
|
|
@@ -347,31 +380,24 @@ var Map = /*#__PURE__*/function (_BaseChart) {
|
|
|
347
380
|
value: function componentDidUpdate(preProps, preState) {
|
|
348
381
|
var _this3 = this;
|
|
349
382
|
if (!this.chart || !this.dataSet) return;
|
|
350
|
-
var
|
|
351
|
-
statItem = _this$props4.statItem,
|
|
352
|
-
chartCalculator = _this$props4.chartCalculator;
|
|
383
|
+
var statItem = this.props.statItem;
|
|
353
384
|
var isCalculatingData = this.state.isCalculatingData;
|
|
354
385
|
if (isCalculatingData !== preState.isCalculatingData) return;
|
|
355
386
|
if (this.shouldCalculateStatItem(preProps, this.props)) {
|
|
356
387
|
this.setState({
|
|
357
388
|
isCalculatingData: true
|
|
358
389
|
});
|
|
359
|
-
if (this.
|
|
360
|
-
|
|
361
|
-
this.
|
|
362
|
-
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
_this3.
|
|
366
|
-
_this3.
|
|
367
|
-
isCalculatingData: false
|
|
368
|
-
});
|
|
369
|
-
_this3.updateStatisticData(_this3.fixData(statData));
|
|
370
|
-
if (_this3.props.isPreview) {
|
|
371
|
-
var canvasSize = _this3.getCanvasSize();
|
|
372
|
-
_this3.chart.changeSize(canvasSize.w, canvasSize.h);
|
|
373
|
-
}
|
|
390
|
+
if (this.hasMapChanged(preProps.statItem, statItem)) {
|
|
391
|
+
this.props.queryMapJson({
|
|
392
|
+
map_level: this.getMapLevel(statItem),
|
|
393
|
+
map_location: statItem.map_location
|
|
394
|
+
}, function (mapJson) {
|
|
395
|
+
if (!mapJson) return;
|
|
396
|
+
_this3.geoData = mapJson;
|
|
397
|
+
_this3.reCalculateChart(statItem);
|
|
374
398
|
});
|
|
399
|
+
} else {
|
|
400
|
+
this.container && this.reCalculateChart(statItem);
|
|
375
401
|
}
|
|
376
402
|
} else {
|
|
377
403
|
this.updateStatisticData(this.fixData(this.calculateData));
|
|
@@ -409,6 +435,7 @@ Map.propTypes = {
|
|
|
409
435
|
statItem: PropTypes.object,
|
|
410
436
|
chartCalculator: PropTypes.object,
|
|
411
437
|
getTableById: PropTypes.func,
|
|
438
|
+
queryMapJson: PropTypes.func.isRequired,
|
|
412
439
|
toggleStatisticRecordsDialog: PropTypes.func
|
|
413
440
|
};
|
|
414
441
|
export default Map;
|
|
@@ -10,6 +10,7 @@ import { TableUtils } from 'dtable-store';
|
|
|
10
10
|
import BaseChart from './base-chart';
|
|
11
11
|
import { Chart } from '../custom-g2';
|
|
12
12
|
import { COLOR_OPTIONS, DEFAULT_NUMBER_FORMAT_OBJECT, STAT_TYPE, SUMMARY_TYPE, TITLE_AMOUNT } from '../constants';
|
|
13
|
+
import { MAP_LEVEL } from '../constants/map';
|
|
13
14
|
var WIDTH = 798;
|
|
14
15
|
var HEIGHT = 394;
|
|
15
16
|
var WorldMap = /*#__PURE__*/function (_BaseChart) {
|
|
@@ -124,11 +125,7 @@ var WorldMap = /*#__PURE__*/function (_BaseChart) {
|
|
|
124
125
|
return _this.getNumberDisplayString(value, summaryColumnData, summary_method);
|
|
125
126
|
}
|
|
126
127
|
},
|
|
127
|
-
|
|
128
|
-
style: {
|
|
129
|
-
'opacity': 0
|
|
130
|
-
}
|
|
131
|
-
}
|
|
128
|
+
slidable: false
|
|
132
129
|
});
|
|
133
130
|
_this.statisticView.interaction('element-active');
|
|
134
131
|
_this.statisticView.render();
|
|
@@ -157,6 +154,9 @@ var WorldMap = /*#__PURE__*/function (_BaseChart) {
|
|
|
157
154
|
}
|
|
158
155
|
_this.statisticView = _this.chart.createView();
|
|
159
156
|
_this.statisticView.data(userDv.rows);
|
|
157
|
+
_this.chart.theme({
|
|
158
|
+
defaultColor: statItem.bubble_color || '#2a67d1'
|
|
159
|
+
});
|
|
160
160
|
_this.statisticView.point().position('longitude*latitude').size('value', function (value) {
|
|
161
161
|
var percent = value / data.sum;
|
|
162
162
|
var size = percent * 100;
|
|
@@ -201,11 +201,7 @@ var WorldMap = /*#__PURE__*/function (_BaseChart) {
|
|
|
201
201
|
return _this.getNumberDisplayString(value, summaryColumnData, summary_method);
|
|
202
202
|
}
|
|
203
203
|
},
|
|
204
|
-
|
|
205
|
-
style: {
|
|
206
|
-
'opacity': 0
|
|
207
|
-
}
|
|
208
|
-
}
|
|
204
|
+
slidable: false
|
|
209
205
|
});
|
|
210
206
|
_this.statisticView.interaction('element-active');
|
|
211
207
|
_this.statisticView.render();
|
|
@@ -329,15 +325,15 @@ var WorldMap = /*#__PURE__*/function (_BaseChart) {
|
|
|
329
325
|
var _this$props3 = this.props,
|
|
330
326
|
statItem = _this$props3.statItem,
|
|
331
327
|
chartCalculator = _this$props3.chartCalculator;
|
|
332
|
-
this.
|
|
333
|
-
|
|
334
|
-
}
|
|
328
|
+
this.props.queryMapJson({
|
|
329
|
+
map_level: MAP_LEVEL.WORLD
|
|
330
|
+
}, function (mapJson) {
|
|
335
331
|
_this2.setState({
|
|
336
332
|
isDataLoaded: true
|
|
337
333
|
});
|
|
338
|
-
if (!
|
|
339
|
-
_this2.geoData =
|
|
340
|
-
_this2.initStatisticContext(
|
|
334
|
+
if (!mapJson) return;
|
|
335
|
+
_this2.geoData = mapJson;
|
|
336
|
+
_this2.initStatisticContext(mapJson);
|
|
341
337
|
if (_this2.container) {
|
|
342
338
|
chartCalculator.calculate(statItem).then(function (calculation) {
|
|
343
339
|
_this2.setState({
|
|
@@ -427,6 +423,7 @@ WorldMap.propTypes = {
|
|
|
427
423
|
statItem: PropTypes.object,
|
|
428
424
|
chartCalculator: PropTypes.object,
|
|
429
425
|
getTableById: PropTypes.func,
|
|
426
|
+
queryMapJson: PropTypes.func.isRequired,
|
|
430
427
|
toggleStatisticRecordsDialog: PropTypes.func
|
|
431
428
|
};
|
|
432
429
|
export default WorldMap;
|
package/es/utils/map.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { GEOLOCATION_GRANULARITY, STAT_TYPE } from '../constants';
|
|
2
|
+
import { MAP_LEVEL, MUNICIPALITIES } from '../constants/map';
|
|
3
|
+
import { regions } from '../constants/regions';
|
|
4
|
+
var COUNTY_SCALE_WIDTH = 5.95;
|
|
5
|
+
var COUNTY_SCALE_HEIGHT = 4.37;
|
|
6
|
+
export var getGeoGranularityByLevel = function getGeoGranularityByLevel(mapLevel) {
|
|
7
|
+
switch (mapLevel) {
|
|
8
|
+
case MAP_LEVEL.PROVINCE:
|
|
9
|
+
{
|
|
10
|
+
return GEOLOCATION_GRANULARITY.CITY;
|
|
11
|
+
}
|
|
12
|
+
case MAP_LEVEL.CITY:
|
|
13
|
+
{
|
|
14
|
+
return GEOLOCATION_GRANULARITY.DISTRICT;
|
|
15
|
+
}
|
|
16
|
+
default:
|
|
17
|
+
{
|
|
18
|
+
// default as 'country'
|
|
19
|
+
return GEOLOCATION_GRANULARITY.PROVINCE;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
export var fixGeoGranularity = function fixGeoGranularity(_ref) {
|
|
24
|
+
var mapLevel = _ref.mapLevel,
|
|
25
|
+
mapLocation = _ref.mapLocation;
|
|
26
|
+
if (!mapLevel || mapLevel === MAP_LEVEL.COUNTRY || !mapLocation) {
|
|
27
|
+
return GEOLOCATION_GRANULARITY.PROVINCE;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// e.g. Beijing
|
|
31
|
+
var provinceName = mapLocation.province,
|
|
32
|
+
cityName = mapLocation.city;
|
|
33
|
+
if (provinceName && MUNICIPALITIES.includes(provinceName)) {
|
|
34
|
+
return GEOLOCATION_GRANULARITY.DISTRICT;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// e.g. HongKong
|
|
38
|
+
var selectedProvince = provinceName && regions.find(function (province) {
|
|
39
|
+
return province.name === provinceName;
|
|
40
|
+
});
|
|
41
|
+
if (selectedProvince && selectedProvince.disable_drill_down) {
|
|
42
|
+
return GEOLOCATION_GRANULARITY.PROVINCE;
|
|
43
|
+
}
|
|
44
|
+
var cities = selectedProvince && selectedProvince.cities;
|
|
45
|
+
var selectedCity = cities && cityName && cities.find(function (city) {
|
|
46
|
+
return city.name === cityName;
|
|
47
|
+
});
|
|
48
|
+
if (mapLevel === MAP_LEVEL.CITY && selectedCity && selectedCity.disable_drill_down) {
|
|
49
|
+
return GEOLOCATION_GRANULARITY.CITY;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// others
|
|
53
|
+
return getGeoGranularityByLevel(mapLevel);
|
|
54
|
+
};
|
|
55
|
+
export var fixMapGeoGranularity = function fixMapGeoGranularity(chart) {
|
|
56
|
+
var type = chart.type,
|
|
57
|
+
map_level = chart.map_level,
|
|
58
|
+
map_location = chart.map_location;
|
|
59
|
+
if (type !== STAT_TYPE.MAP && type !== STAT_TYPE.MAP_BUBBLE) {
|
|
60
|
+
return chart.geolocation_granularity;
|
|
61
|
+
}
|
|
62
|
+
return fixGeoGranularity({
|
|
63
|
+
mapLevel: map_level,
|
|
64
|
+
mapLocation: map_location
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
export var getRegionScaleOffsets = function getRegionScaleOffsets(mapLevel, mapLocation) {
|
|
68
|
+
var countryScaleOffsets = {
|
|
69
|
+
scale_w: COUNTY_SCALE_WIDTH,
|
|
70
|
+
scale_h: COUNTY_SCALE_HEIGHT
|
|
71
|
+
};
|
|
72
|
+
switch (mapLevel) {
|
|
73
|
+
case MAP_LEVEL.PROVINCE:
|
|
74
|
+
{
|
|
75
|
+
var provinceName = mapLocation && mapLocation.province;
|
|
76
|
+
var province = provinceName && regions.find(function (province) {
|
|
77
|
+
return province.name === provinceName;
|
|
78
|
+
});
|
|
79
|
+
if (!province) return countryScaleOffsets;
|
|
80
|
+
return {
|
|
81
|
+
scale_w: province.scale_w,
|
|
82
|
+
scale_h: province.scale_h
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
case MAP_LEVEL.CITY:
|
|
86
|
+
{
|
|
87
|
+
var _provinceName = mapLocation && mapLocation.province;
|
|
88
|
+
var _province = _provinceName && regions.find(function (province) {
|
|
89
|
+
return province.name === _provinceName;
|
|
90
|
+
});
|
|
91
|
+
var cities = _province && _province.cities;
|
|
92
|
+
var cityName = mapLocation.city;
|
|
93
|
+
var city = cityName && Array.isArray(cities) && cities.find(function (city) {
|
|
94
|
+
return city.name === cityName;
|
|
95
|
+
});
|
|
96
|
+
if (!city) return countryScaleOffsets;
|
|
97
|
+
return {
|
|
98
|
+
scale_w: city.scale_w,
|
|
99
|
+
scale_h: city.scale_h
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
default:
|
|
103
|
+
{
|
|
104
|
+
// default as 'country'
|
|
105
|
+
return countryScaleOffsets;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dtable-statistic",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.4",
|
|
4
4
|
"description": "statistics",
|
|
5
5
|
"main": "dist/dtable-statistic.js",
|
|
6
6
|
"author": "seafile",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"@seafile/seafile-calendar": "0.0.24",
|
|
13
13
|
"comlink": "^4.3.1",
|
|
14
14
|
"dayjs": "1.10.7",
|
|
15
|
-
"dtable-store": "4.1.
|
|
16
|
-
"dtable-web-api": "4.0.
|
|
15
|
+
"dtable-store": "4.1.2",
|
|
16
|
+
"dtable-web-api": "4.0.11",
|
|
17
17
|
"glamor": "^2.20.40",
|
|
18
18
|
"html2canvas": "^1.4.1",
|
|
19
19
|
"rc-slider": "^9.7.4",
|