dtable-statistic 4.1.1 → 4.1.3

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.
@@ -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", {
@@ -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
@@ -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;
@@ -9,6 +9,8 @@ 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
+ import { MAP_LEVEL } from '../constants/map';
13
+ import { shallowEqual } from '../utils/common-utils';
12
14
  var WIDTH = 798;
13
15
  var HEIGHT = 520;
14
16
  var Map = /*#__PURE__*/function (_BaseChart) {
@@ -18,6 +20,34 @@ var Map = /*#__PURE__*/function (_BaseChart) {
18
20
  var _this;
19
21
  _classCallCheck(this, Map);
20
22
  _this = _super.call(this, props);
23
+ _this.hasMapChanged = function (preStatItem, statItem) {
24
+ var preMapLevel = preStatItem.map_level,
25
+ prevMapLocation = preStatItem.map_location;
26
+ var map_level = statItem.map_level,
27
+ map_location = statItem.map_location;
28
+ return map_level !== preMapLevel || !shallowEqual(map_location, prevMapLocation);
29
+ };
30
+ _this.reCalculateChart = function (statItem) {
31
+ if (_this.chart) {
32
+ _this.chart.destroy();
33
+ _this.initStatisticContext(_this.geoData);
34
+ }
35
+ _this.props.chartCalculator.calculate(statItem).then(function (statData) {
36
+ _this.calculateData = statData;
37
+ _this.setState({
38
+ isCalculatingData: false
39
+ });
40
+ _this.updateStatisticData(_this.fixData(statData));
41
+ if (_this.props.isPreview) {
42
+ var canvasSize = _this.getCanvasSize();
43
+ _this.chart.changeSize(canvasSize.w, canvasSize.h);
44
+ }
45
+ });
46
+ };
47
+ _this.getMapLevel = function (statItem) {
48
+ var map_level = statItem.map_level;
49
+ return map_level || MAP_LEVEL.COUNTRY;
50
+ };
21
51
  _this.fixData = function (statisticData) {
22
52
  if (!statisticData) return [];
23
53
  var statisticNewData = [];
@@ -292,10 +322,6 @@ var Map = /*#__PURE__*/function (_BaseChart) {
292
322
  _this.dataSet.createView('statisticViewModel');
293
323
  mapView.render();
294
324
  };
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
325
  _this.state = {
300
326
  isDataLoaded: false,
301
327
  isCalculatingData: true
@@ -310,15 +336,18 @@ var Map = /*#__PURE__*/function (_BaseChart) {
310
336
  var _this$props3 = this.props,
311
337
  statItem = _this$props3.statItem,
312
338
  chartCalculator = _this$props3.chartCalculator;
313
- this.getGeoLocationData().then(function (res) {
314
- return res && res.json();
315
- }).then(function (data) {
339
+ var map_location = statItem.map_location;
340
+ var mapLevel = this.getMapLevel(statItem);
341
+ this.props.queryMapJson({
342
+ map_level: mapLevel,
343
+ map_location: map_location
344
+ }, function (mapJson) {
316
345
  _this2.setState({
317
346
  isDataLoaded: true
318
347
  }, function () {
319
- if (!data) return;
320
- _this2.geoData = data;
321
- _this2.initStatisticContext(data);
348
+ if (!mapJson) return;
349
+ _this2.geoData = mapJson;
350
+ _this2.initStatisticContext(mapJson);
322
351
  if (_this2.container) {
323
352
  chartCalculator.calculate(statItem).then(function (data) {
324
353
  _this2.calculateData = data;
@@ -347,31 +376,24 @@ var Map = /*#__PURE__*/function (_BaseChart) {
347
376
  value: function componentDidUpdate(preProps, preState) {
348
377
  var _this3 = this;
349
378
  if (!this.chart || !this.dataSet) return;
350
- var _this$props4 = this.props,
351
- statItem = _this$props4.statItem,
352
- chartCalculator = _this$props4.chartCalculator;
379
+ var statItem = this.props.statItem;
353
380
  var isCalculatingData = this.state.isCalculatingData;
354
381
  if (isCalculatingData !== preState.isCalculatingData) return;
355
382
  if (this.shouldCalculateStatItem(preProps, this.props)) {
356
383
  this.setState({
357
384
  isCalculatingData: true
358
385
  });
359
- if (this.container) {
360
- if (this.chart) {
361
- this.chart.destroy();
362
- this.initStatisticContext(this.geoData);
363
- }
364
- chartCalculator.calculate(statItem).then(function (statData) {
365
- _this3.calculateData = statData;
366
- _this3.setState({
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
- }
386
+ if (this.hasMapChanged(preProps.statItem, statItem)) {
387
+ this.props.queryMapJson({
388
+ map_level: this.getMapLevel(statItem),
389
+ map_location: statItem.map_location
390
+ }, function (mapJson) {
391
+ if (!mapJson) return;
392
+ _this3.geoData = mapJson;
393
+ _this3.reCalculateChart(statItem);
374
394
  });
395
+ } else {
396
+ this.container && this.reCalculateChart(statItem);
375
397
  }
376
398
  } else {
377
399
  this.updateStatisticData(this.fixData(this.calculateData));
@@ -409,6 +431,7 @@ Map.propTypes = {
409
431
  statItem: PropTypes.object,
410
432
  chartCalculator: PropTypes.object,
411
433
  getTableById: PropTypes.func,
434
+ queryMapJson: PropTypes.func.isRequired,
412
435
  toggleStatisticRecordsDialog: PropTypes.func
413
436
  };
414
437
  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) {
@@ -329,15 +330,15 @@ var WorldMap = /*#__PURE__*/function (_BaseChart) {
329
330
  var _this$props3 = this.props,
330
331
  statItem = _this$props3.statItem,
331
332
  chartCalculator = _this$props3.chartCalculator;
332
- this.getGeoLocationData().then(function (res) {
333
- return res && res.json();
334
- }).then(function (data) {
333
+ this.props.queryMapJson({
334
+ map_level: MAP_LEVEL.WORLD
335
+ }, function (mapJson) {
335
336
  _this2.setState({
336
337
  isDataLoaded: true
337
338
  });
338
- if (!data) return;
339
- _this2.geoData = data;
340
- _this2.initStatisticContext(data);
339
+ if (!mapJson) return;
340
+ _this2.geoData = mapJson;
341
+ _this2.initStatisticContext(mapJson);
341
342
  if (_this2.container) {
342
343
  chartCalculator.calculate(statItem).then(function (calculation) {
343
344
  _this2.setState({
@@ -427,6 +428,7 @@ WorldMap.propTypes = {
427
428
  statItem: PropTypes.object,
428
429
  chartCalculator: PropTypes.object,
429
430
  getTableById: PropTypes.func,
431
+ queryMapJson: PropTypes.func.isRequired,
430
432
  toggleStatisticRecordsDialog: PropTypes.func
431
433
  };
432
434
  export default WorldMap;
@@ -0,0 +1,64 @@
1
+ import { GEOLOCATION_GRANULARITY, STAT_TYPE } from '../constants';
2
+ import { MAP_LEVEL, MUNICIPALITIES } from '../constants/map';
3
+ import { regions } from '../constants/regions';
4
+ export var getGeoGranularityByLevel = function getGeoGranularityByLevel(mapLevel) {
5
+ switch (mapLevel) {
6
+ case MAP_LEVEL.PROVINCE:
7
+ {
8
+ return GEOLOCATION_GRANULARITY.CITY;
9
+ }
10
+ case MAP_LEVEL.CITY:
11
+ {
12
+ return GEOLOCATION_GRANULARITY.DISTRICT;
13
+ }
14
+ default:
15
+ {
16
+ // default as 'country'
17
+ return GEOLOCATION_GRANULARITY.PROVINCE;
18
+ }
19
+ }
20
+ };
21
+ export var fixGeoGranularity = function fixGeoGranularity(_ref) {
22
+ var mapLevel = _ref.mapLevel,
23
+ mapLocation = _ref.mapLocation;
24
+ if (!mapLevel || mapLevel === MAP_LEVEL.COUNTRY || !mapLocation) {
25
+ return GEOLOCATION_GRANULARITY.PROVINCE;
26
+ }
27
+
28
+ // e.g. Beijing
29
+ var provinceName = mapLocation.province,
30
+ cityName = mapLocation.city;
31
+ if (provinceName && MUNICIPALITIES.includes(provinceName)) {
32
+ return GEOLOCATION_GRANULARITY.DISTRICT;
33
+ }
34
+
35
+ // e.g. HongKong
36
+ var selectedProvince = provinceName && regions.find(function (province) {
37
+ return province.name === provinceName;
38
+ });
39
+ if (selectedProvince && selectedProvince.disable_drill_down) {
40
+ return GEOLOCATION_GRANULARITY.PROVINCE;
41
+ }
42
+ var cities = selectedProvince && selectedProvince.cities;
43
+ var selectedCity = cities && cityName && cities.find(function (city) {
44
+ return city.name === cityName;
45
+ });
46
+ if (mapLevel === MAP_LEVEL.CITY && selectedCity && selectedCity.disable_drill_down) {
47
+ return GEOLOCATION_GRANULARITY.CITY;
48
+ }
49
+
50
+ // others
51
+ return getGeoGranularityByLevel(mapLevel);
52
+ };
53
+ export var fixMapGeoGranularity = function fixMapGeoGranularity(chart) {
54
+ var type = chart.type,
55
+ map_level = chart.map_level,
56
+ map_location = chart.map_location;
57
+ if (type !== STAT_TYPE.MAP && type !== STAT_TYPE.MAP_BUBBLE) {
58
+ return chart.geolocation_granularity;
59
+ }
60
+ return fixGeoGranularity({
61
+ mapLevel: map_level,
62
+ mapLocation: map_location
63
+ });
64
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtable-statistic",
3
- "version": "4.1.1",
3
+ "version": "4.1.3",
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.0",
16
- "dtable-web-api": "4.0.5",
15
+ "dtable-store": "4.1.1",
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",
@@ -25,6 +25,9 @@
25
25
  "react-select": "^3.1.0",
26
26
  "reactstrap": "8.9.0"
27
27
  },
28
+ "peerDependencies": {
29
+ "@antv/scale": "0.3.14"
30
+ },
28
31
  "scripts": {
29
32
  "clean:esm": "rm -rf es && mkdir es",
30
33
  "clean:lib": "rm -rf lib && mkdir lib",