dtable-utils 5.0.20 → 5.0.21-beta.11
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/index.js +1 -1
- package/es/archive/clause-module/search.js +1 -0
- package/es/cell-value-get/cell-value.js +0 -4
- package/es/cell-value-get/geolocation.js +41 -7
- package/es/cell-value-set/geolocation.js +135 -26
- package/es/constants/geolocation.js +17 -0
- package/es/date.js +11 -2
- package/es/group/group-row.js +21 -8
- package/es/view/summaries.js +1 -0
- package/lib/archive/clause-module/search.js +1 -0
- package/lib/cell-value-get/cell-value.js +0 -4
- package/lib/cell-value-get/geolocation.js +42 -6
- package/lib/cell-value-set/geolocation.js +142 -25
- package/lib/constants/geolocation.js +23 -0
- package/lib/date.js +11 -2
- package/lib/group/group-row.js +21 -8
- package/lib/view/summaries.js +1 -0
- package/package.json +1 -1
|
@@ -14,6 +14,7 @@ import '@babel/runtime/helpers/typeof';
|
|
|
14
14
|
import '../../date.js';
|
|
15
15
|
import '@babel/runtime/helpers/defineProperty';
|
|
16
16
|
import '@babel/runtime/helpers/toConsumableArray';
|
|
17
|
+
import '@babel/runtime/helpers/slicedToArray';
|
|
17
18
|
|
|
18
19
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
19
20
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
@@ -131,7 +131,6 @@ var getFormulaDisplayString = function getFormulaDisplayString(cellValue, column
|
|
|
131
131
|
* @param {object} formulaRows formula results of rows. Default as "{}"
|
|
132
132
|
* @param {array} collaborators e.g. [{ email, name, ... }, ...]. Default as "[]"
|
|
133
133
|
* @param {array} departments e.g. [{ name, id }, ...]. Default as "[]"
|
|
134
|
-
* @param {bool} isBaiduMap Determine the way to connect latitude and longitude. Default as true
|
|
135
134
|
* @param {string} geolocationHyphen Used as a connector between province, city, district and detail. Default as empty string
|
|
136
135
|
* @returns formatted cell value, string|array
|
|
137
136
|
*/
|
|
@@ -144,8 +143,6 @@ var getCellValueDisplayString = function getCellValueDisplayString(row, type, ke
|
|
|
144
143
|
collaborators = _ref2$collaborators === void 0 ? [] : _ref2$collaborators,
|
|
145
144
|
_ref2$departments = _ref2.departments,
|
|
146
145
|
departments = _ref2$departments === void 0 ? [] : _ref2$departments,
|
|
147
|
-
_ref2$isBaiduMap = _ref2.isBaiduMap,
|
|
148
|
-
isBaiduMap = _ref2$isBaiduMap === void 0 ? true : _ref2$isBaiduMap,
|
|
149
146
|
_ref2$geolocationHyph = _ref2.geolocationHyphen,
|
|
150
147
|
geolocationHyphen = _ref2$geolocationHyph === void 0 ? '' : _ref2$geolocationHyph;
|
|
151
148
|
if (!row) return '';
|
|
@@ -166,7 +163,6 @@ var getCellValueDisplayString = function getCellValueDisplayString(row, type, ke
|
|
|
166
163
|
case CellType.GEOLOCATION:
|
|
167
164
|
{
|
|
168
165
|
return getGeolocationDisplayString(cellValue, data, {
|
|
169
|
-
isBaiduMap: isBaiduMap,
|
|
170
166
|
hyphen: geolocationHyphen
|
|
171
167
|
});
|
|
172
168
|
}
|
|
@@ -1,19 +1,54 @@
|
|
|
1
1
|
import { GROUP_GEOLOCATION_GRANULARITY } from '../constants/group.js';
|
|
2
2
|
import { GEOLOCATION_FORMAT } from '../constants/column.js';
|
|
3
|
-
import {
|
|
3
|
+
import { isNumber } from '../number.js';
|
|
4
|
+
import { DMS_SPLITTER_TYPE, LAT_DIRECTION_TYPE, LNG_DIRECTION_TYPE } from '../constants/geolocation.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Convert decimal to DMS
|
|
8
|
+
* @param {number} lat
|
|
9
|
+
* @param {bool} isLat Latitude: N/S, Longitude: E/W
|
|
10
|
+
* @returns { dms, direction }, object
|
|
11
|
+
*/
|
|
12
|
+
var convertToDMS = function convertToDMS(decimal) {
|
|
13
|
+
var isLat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
14
|
+
if (!isNumber(decimal) && typeof decimal !== 'string') return {};
|
|
15
|
+
var numDecimal = typeof decimal === 'string' ? Number.parseFloat(decimal) : decimal;
|
|
16
|
+
if (!isNumber(numDecimal)) return {};
|
|
17
|
+
var degrees = Math.floor(Math.abs(numDecimal));
|
|
18
|
+
var minutesDecimal = Number.parseFloat(((Math.abs(numDecimal) - degrees) * 60).toFixed(8));
|
|
19
|
+
var minutes = Math.floor(minutesDecimal);
|
|
20
|
+
var seconds = Number.parseFloat(((minutesDecimal - minutes) * 60).toFixed(8));
|
|
21
|
+
var direction = '';
|
|
22
|
+
if (isLat) {
|
|
23
|
+
direction = numDecimal >= 0 ? LAT_DIRECTION_TYPE.N : LAT_DIRECTION_TYPE.S;
|
|
24
|
+
} else {
|
|
25
|
+
direction = numDecimal >= 0 ? LNG_DIRECTION_TYPE.E : LNG_DIRECTION_TYPE.W;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
dms: "".concat(degrees).concat(DMS_SPLITTER_TYPE.DEG).concat(minutes).concat(DMS_SPLITTER_TYPE.MIN).concat(seconds).concat(DMS_SPLITTER_TYPE.SEC),
|
|
29
|
+
direction: direction
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
var getLatLngDisplayString = function getLatLngDisplayString(lat, lng) {
|
|
33
|
+
var _convertToDMS = convertToDMS(lat, true),
|
|
34
|
+
lat_dms = _convertToDMS.dms,
|
|
35
|
+
lat_direction = _convertToDMS.direction;
|
|
36
|
+
var _convertToDMS2 = convertToDMS(lng),
|
|
37
|
+
lng_dms = _convertToDMS2.dms,
|
|
38
|
+
lng_direction = _convertToDMS2.direction;
|
|
39
|
+
if (!lat_dms || !lng_dms) return '';
|
|
40
|
+
return "".concat(lat_direction).concat(lat_dms, ", ").concat(lng_direction).concat(lng_dms);
|
|
41
|
+
};
|
|
4
42
|
|
|
5
43
|
/**
|
|
6
44
|
* Get formatted geolocation
|
|
7
45
|
* @param {object} loc
|
|
8
46
|
* @param {object} formats , e.g. { geo_format, ... }
|
|
9
|
-
* @param {bool} isBaiduMap Determine the way to connect latitude and longitude. Default as true
|
|
10
47
|
* @param {string} hyphen Used as a connector between province, city, district and detail. Default as empty string
|
|
11
48
|
* @returns formatted geolocation, string
|
|
12
49
|
*/
|
|
13
50
|
var getGeolocationDisplayString = function getGeolocationDisplayString(loc, formats) {
|
|
14
51
|
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
15
|
-
_ref$isBaiduMap = _ref.isBaiduMap,
|
|
16
|
-
isBaiduMap = _ref$isBaiduMap === void 0 ? true : _ref$isBaiduMap,
|
|
17
52
|
_ref$hyphen = _ref.hyphen,
|
|
18
53
|
hyphen = _ref$hyphen === void 0 ? '' : _ref$hyphen;
|
|
19
54
|
if (!loc) return '';
|
|
@@ -24,8 +59,7 @@ var getGeolocationDisplayString = function getGeolocationDisplayString(loc, form
|
|
|
24
59
|
{
|
|
25
60
|
var lng = loc.lng,
|
|
26
61
|
lat = loc.lat;
|
|
27
|
-
|
|
28
|
-
return isBaiduMap ? "".concat(lng, ", ").concat(lat) : "".concat(lat, ", ").concat(lng);
|
|
62
|
+
return getLatLngDisplayString(lat, lng);
|
|
29
63
|
}
|
|
30
64
|
case GEOLOCATION_FORMAT.COUNTRY_REGION:
|
|
31
65
|
{
|
|
@@ -101,4 +135,4 @@ var getGeolocationByGranularity = function getGeolocationByGranularity(geolocati
|
|
|
101
135
|
}
|
|
102
136
|
};
|
|
103
137
|
|
|
104
|
-
export { getGeolocationByGranularity, getGeolocationDisplayString };
|
|
138
|
+
export { convertToDMS, getGeolocationByGranularity, getGeolocationDisplayString, getLatLngDisplayString };
|
|
@@ -1,39 +1,148 @@
|
|
|
1
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
|
+
import { GEOLOCATION_FORMAT } from '../constants/column.js';
|
|
3
|
+
import '../constants/filter/filter-column-options.js';
|
|
4
|
+
import '../constants/filter/filter-modifier.js';
|
|
5
|
+
import '../constants/filter/filter-predicate.js';
|
|
6
|
+
import '../constants/filter/filter-is-within.js';
|
|
7
|
+
import '../constants/formula.js';
|
|
8
|
+
import '../constants/sort.js';
|
|
9
|
+
import '../constants/group.js';
|
|
10
|
+
import { LAT_DIRECTION_TYPE, LNG_DIRECTION_TYPE, DMS_SPLITTER_TYPE } from '../constants/geolocation.js';
|
|
11
|
+
import { isNumber } from '../number.js';
|
|
12
|
+
|
|
1
13
|
var provinceReg = /.+省|.+自治区|.+特别行政区|北京市|天津市|上海市|重庆市|安徽|福建|甘肃|广东|广西|贵州|海南|河北|河南|黑龙江|湖北|湖南|吉林|江苏|江西|辽宁|内蒙古|宁夏|青海|山东|山西|陕西|四川|西藏|新疆|云南|浙江|北京|上海|天津|重庆/;
|
|
2
14
|
var cityReg = /.+自治州|[^市]+市|.+盟|.+地区|.+区划/;
|
|
3
15
|
var districtReg = /(.+市|.+县|.+旗|.+区)/;
|
|
16
|
+
var LNG_LAT_REG = /^-?([1-9]\d*\.\d+|0\.\d+|[1-9]\d*|0)$/;
|
|
17
|
+
var DMS_DEG_REG = new RegExp("(\\d+(?:\\.\\d+)?)".concat(DMS_SPLITTER_TYPE.DEG));
|
|
18
|
+
var DMS_MIN_REG = new RegExp("(\\d+(?:\\.\\d+)?)".concat(DMS_SPLITTER_TYPE.MIN));
|
|
19
|
+
var DMS_SEC_REG = new RegExp("(\\d+(?:\\.\\d+)?)".concat(DMS_SPLITTER_TYPE.SEC));
|
|
20
|
+
var parseDMS = function parseDMS(dms, direction) {
|
|
21
|
+
if (typeof dms !== 'string') {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
var degMatches = dms.match(DMS_DEG_REG);
|
|
25
|
+
var minMatches = dms.match(DMS_MIN_REG);
|
|
26
|
+
var secMatches = dms.match(DMS_SEC_REG);
|
|
27
|
+
var strDeg = degMatches && degMatches[1];
|
|
28
|
+
var strMin = minMatches && minMatches[1];
|
|
29
|
+
var strSec = secMatches && secMatches[1];
|
|
30
|
+
if (!strDeg && !strMin && !strSec) {
|
|
31
|
+
// invalid DMS
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
var deg = Number.parseFloat(strDeg);
|
|
35
|
+
var min = Number.parseFloat(strMin);
|
|
36
|
+
var sec = Number.parseFloat(strSec);
|
|
37
|
+
if (!isNumber(deg) && !isNumber(min) && !isNumber(sec)) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
deg = deg || 0;
|
|
41
|
+
min = min || 0;
|
|
42
|
+
sec = sec || 0;
|
|
43
|
+
var decimal = deg + min / 60 + sec / 3600;
|
|
44
|
+
if (direction === LAT_DIRECTION_TYPE.S || direction === LNG_DIRECTION_TYPE.W) {
|
|
45
|
+
return -Math.abs(decimal);
|
|
46
|
+
}
|
|
47
|
+
return decimal;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Parse LatLng-DMS string to degree
|
|
52
|
+
* e.g. 'N30°50′50.55″, E30.50′50.55″'
|
|
53
|
+
* @param {string} strLatLng
|
|
54
|
+
* @returns { lat, lng }, object
|
|
55
|
+
*/
|
|
56
|
+
var parseLatLngDMS = function parseLatLngDMS(strLatLngDMS) {
|
|
57
|
+
if (typeof strLatLngDMS !== 'string') {
|
|
58
|
+
return {};
|
|
59
|
+
}
|
|
60
|
+
var _strLatLngDMS$split$m = strLatLngDMS.split(',').map(function (str) {
|
|
61
|
+
return str ? str.trim() : '';
|
|
62
|
+
}),
|
|
63
|
+
_strLatLngDMS$split$m2 = _slicedToArray(_strLatLngDMS$split$m, 2),
|
|
64
|
+
strLatDMS = _strLatLngDMS$split$m2[0],
|
|
65
|
+
strLngDMS = _strLatLngDMS$split$m2[1];
|
|
66
|
+
if (!strLatDMS || !strLngDMS) {
|
|
67
|
+
// invalid LatLng DMS
|
|
68
|
+
return {};
|
|
69
|
+
}
|
|
70
|
+
var latDirection = strLatDMS[0];
|
|
71
|
+
var lngDirection = strLngDMS[0];
|
|
72
|
+
if (!latDirection || !lngDirection || latDirection !== LAT_DIRECTION_TYPE.N && latDirection !== LAT_DIRECTION_TYPE.S || lngDirection !== LNG_DIRECTION_TYPE.E && lngDirection !== LNG_DIRECTION_TYPE.W) {
|
|
73
|
+
// invalid lat/lng direction
|
|
74
|
+
return {};
|
|
75
|
+
}
|
|
76
|
+
var strLat = strLatDMS.substring(1);
|
|
77
|
+
var strLng = strLngDMS.substring(1);
|
|
78
|
+
var lat = parseDMS(strLat, latDirection);
|
|
79
|
+
var lng = parseDMS(strLng, lngDirection);
|
|
80
|
+
if (!isNumber(lat) || !isNumber(lng)) {
|
|
81
|
+
return {};
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
lat: lat,
|
|
85
|
+
lng: lng
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Parse LatLng-DMS string to degree
|
|
91
|
+
* e.g. '30.50, 30.50'
|
|
92
|
+
* @param {string} strLatLng
|
|
93
|
+
* @returns { lat, lng }, object
|
|
94
|
+
*/
|
|
95
|
+
var parseLngLatDegree = function parseLngLatDegree(strLngLat) {
|
|
96
|
+
// match floating point numbers
|
|
97
|
+
// ^[1-9]\d*\.\d+$ --> floating point type that does not start with 0
|
|
98
|
+
// ^0\.\d+$ --> floating point type starting with 0
|
|
99
|
+
// ^[1-9]\d*$ --> non-zero integer
|
|
100
|
+
// 0
|
|
101
|
+
if (typeof strLngLat !== 'string') {
|
|
102
|
+
return {};
|
|
103
|
+
}
|
|
104
|
+
var _strLngLat$split$map = strLngLat.split(',').map(function (str) {
|
|
105
|
+
return str ? str.trim() : '';
|
|
106
|
+
}),
|
|
107
|
+
_strLngLat$split$map2 = _slicedToArray(_strLngLat$split$map, 2),
|
|
108
|
+
strLng = _strLngLat$split$map2[0],
|
|
109
|
+
strLat = _strLngLat$split$map2[1];
|
|
110
|
+
if (!strLng || !strLat || !strLng.match(LNG_LAT_REG) || !strLat.match(LNG_LAT_REG)) {
|
|
111
|
+
return {};
|
|
112
|
+
}
|
|
113
|
+
var numLng = Number(strLng);
|
|
114
|
+
var numLat = Number(strLat);
|
|
115
|
+
if (!isNumber(numLng) || !isNumber(numLat)) {
|
|
116
|
+
return {};
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
lat: numLat,
|
|
120
|
+
lng: numLng
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Parse LatLng-DMS/LngLat-Degree string to degree
|
|
126
|
+
* @param {string} strLatLng
|
|
127
|
+
* @returns { lat, lng }, object
|
|
128
|
+
*/
|
|
129
|
+
var parseLatLng = function parseLatLng(strLatLng) {
|
|
130
|
+
if (strLatLng && (strLatLng.includes(LAT_DIRECTION_TYPE.N) && strLatLng.includes(LNG_DIRECTION_TYPE.E) || strLatLng.includes(LAT_DIRECTION_TYPE.S) && strLatLng.includes(LNG_DIRECTION_TYPE.W))) {
|
|
131
|
+
return parseLatLngDMS(strLatLng);
|
|
132
|
+
}
|
|
133
|
+
return parseLngLatDegree(strLatLng);
|
|
134
|
+
};
|
|
4
135
|
var formatTextToGeolocation = function formatTextToGeolocation(value, columnData) {
|
|
5
136
|
// compatible with the old version, the old version data may be null or undefined
|
|
6
137
|
var _ref = columnData || {},
|
|
7
138
|
_ref$geo_format = _ref.geo_format,
|
|
8
|
-
geo_format = _ref$geo_format === void 0 ?
|
|
139
|
+
geo_format = _ref$geo_format === void 0 ? GEOLOCATION_FORMAT.GEOLOCATION : _ref$geo_format;
|
|
9
140
|
var cellValue = value || '';
|
|
10
141
|
if (cellValue.length < 3) {
|
|
11
142
|
return {};
|
|
12
143
|
}
|
|
13
|
-
if (geo_format ===
|
|
14
|
-
|
|
15
|
-
// ^[1-9]\d*\.\d+$ --> floating point type that does not start with 0
|
|
16
|
-
// ^0\.\d+$ --> floating point type starting with 0
|
|
17
|
-
// ^[1-9]\d*$ --> non-zero integer
|
|
18
|
-
// 0
|
|
19
|
-
var reg = /^-?([1-9]\d*\.\d+|0\.\d+|[1-9]\d*|0)$/;
|
|
20
|
-
if (cellValue.indexOf(',') < 0) return {};
|
|
21
|
-
var lng_lat = cellValue.split(',');
|
|
22
|
-
if (lng_lat.length !== 2) {
|
|
23
|
-
return {};
|
|
24
|
-
}
|
|
25
|
-
var lng = lng_lat[0].trim();
|
|
26
|
-
var lat = lng_lat[1].trim();
|
|
27
|
-
if (!lng || !lat) {
|
|
28
|
-
return {};
|
|
29
|
-
}
|
|
30
|
-
if (!lng.match(reg) || !lat.match(reg)) {
|
|
31
|
-
return {};
|
|
32
|
-
}
|
|
33
|
-
return {
|
|
34
|
-
lng: lng,
|
|
35
|
-
lat: lat
|
|
36
|
-
};
|
|
144
|
+
if (geo_format === GEOLOCATION_FORMAT.LNG_LAT) {
|
|
145
|
+
return parseLatLng(cellValue);
|
|
37
146
|
}
|
|
38
147
|
var matchedProvince = cellValue.match(provinceReg);
|
|
39
148
|
var province = '';
|
|
@@ -65,4 +174,4 @@ var formatTextToGeolocation = function formatTextToGeolocation(value, columnData
|
|
|
65
174
|
};
|
|
66
175
|
};
|
|
67
176
|
|
|
68
|
-
export { formatTextToGeolocation };
|
|
177
|
+
export { formatTextToGeolocation, parseDMS, parseLatLng, parseLatLngDMS, parseLngLatDegree };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var LAT_DIRECTION_TYPE = {
|
|
2
|
+
N: 'N',
|
|
3
|
+
// North
|
|
4
|
+
S: 'S' // South
|
|
5
|
+
};
|
|
6
|
+
var LNG_DIRECTION_TYPE = {
|
|
7
|
+
E: 'E',
|
|
8
|
+
// East
|
|
9
|
+
W: 'W' // West
|
|
10
|
+
};
|
|
11
|
+
var DMS_SPLITTER_TYPE = {
|
|
12
|
+
DEG: '°',
|
|
13
|
+
MIN: '′',
|
|
14
|
+
SEC: '″'
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { DMS_SPLITTER_TYPE, LAT_DIRECTION_TYPE, LNG_DIRECTION_TYPE };
|
package/es/date.js
CHANGED
|
@@ -34,6 +34,11 @@ var MATCHER_EXPRESSIONS = {
|
|
|
34
34
|
YYYY: [MATCH4, DATE_UNIT.YEAR]
|
|
35
35
|
};
|
|
36
36
|
var MATCHER_DATE_PARTS = ['YYYY', 'MM', 'M', 'DD', 'D'];
|
|
37
|
+
var WEEK_DAY_TO_NUM_MAP = {
|
|
38
|
+
Monday: 1,
|
|
39
|
+
Saturday: 6,
|
|
40
|
+
Sunday: 0
|
|
41
|
+
};
|
|
37
42
|
var DateUtils = /*#__PURE__*/function () {
|
|
38
43
|
function DateUtils() {
|
|
39
44
|
_classCallCheck(this, DateUtils);
|
|
@@ -88,13 +93,15 @@ var DateUtils = /*#__PURE__*/function () {
|
|
|
88
93
|
* returns the formatted date with granularity.
|
|
89
94
|
* @param {string|date object} date
|
|
90
95
|
* @param {string} granularity
|
|
96
|
+
* @param {string} firstDayOfWeek - 'Saturday','Sunday' or 'Monday', default is Monday
|
|
91
97
|
* @returns formatted date
|
|
92
98
|
*/
|
|
93
99
|
}, {
|
|
94
100
|
key: "getDateByGranularity",
|
|
95
101
|
value: function getDateByGranularity(date, granularity) {
|
|
102
|
+
var firstDayOfWeek = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'Monday';
|
|
96
103
|
var dateObject = this.getValidDate(date);
|
|
97
|
-
if (!dateObject) {
|
|
104
|
+
if (!dateObject || !Object.keys(WEEK_DAY_TO_NUM_MAP).includes(firstDayOfWeek)) {
|
|
98
105
|
return '';
|
|
99
106
|
}
|
|
100
107
|
var upperCaseGranularity = granularity && granularity.toUpperCase();
|
|
@@ -118,8 +125,10 @@ var DateUtils = /*#__PURE__*/function () {
|
|
|
118
125
|
}
|
|
119
126
|
case 'WEEK':
|
|
120
127
|
{
|
|
128
|
+
var firstDayOfWeekNum = WEEK_DAY_TO_NUM_MAP[firstDayOfWeek];
|
|
121
129
|
var weekNum = dateObject.getDay();
|
|
122
|
-
var
|
|
130
|
+
var daysToFirstDay = (weekNum - firstDayOfWeekNum + 7) % 7;
|
|
131
|
+
var startOfWeekDay = dateObject.getDate() - daysToFirstDay;
|
|
123
132
|
var startOfWeekDate = new Date(year, dateObject.getMonth(), startOfWeekDay);
|
|
124
133
|
var _month2 = startOfWeekDate.getMonth() + 1;
|
|
125
134
|
var day = startOfWeekDate.getDate();
|
package/es/group/group-row.js
CHANGED
|
@@ -43,6 +43,7 @@ var _getCellValue = function _getCellValue(row, formulaRows, groupby) {
|
|
|
43
43
|
return cellValue;
|
|
44
44
|
};
|
|
45
45
|
var _getFormattedCellValue = function _getFormattedCellValue(cellValue, groupby) {
|
|
46
|
+
var firstDayOfWeek = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'Monday';
|
|
46
47
|
var column = groupby.column,
|
|
47
48
|
countType = groupby.count_type;
|
|
48
49
|
var columnType = column.type,
|
|
@@ -61,7 +62,7 @@ var _getFormattedCellValue = function _getFormattedCellValue(cellValue, groupby)
|
|
|
61
62
|
case CellType.CTIME:
|
|
62
63
|
case CellType.MTIME:
|
|
63
64
|
{
|
|
64
|
-
return DateUtils.getDateByGranularity(cellValue, countType) || null;
|
|
65
|
+
return DateUtils.getDateByGranularity(cellValue, countType, firstDayOfWeek) || null;
|
|
65
66
|
}
|
|
66
67
|
case CellType.NUMBER:
|
|
67
68
|
case CellType.DURATION:
|
|
@@ -98,7 +99,7 @@ var _getFormattedCellValue = function _getFormattedCellValue(cellValue, groupby)
|
|
|
98
99
|
return cellValue || cellValue === 0 ? cellValue : null;
|
|
99
100
|
}
|
|
100
101
|
if (result_type === FORMULA_RESULT_TYPE.DATE) {
|
|
101
|
-
return DateUtils.getDateByGranularity(cellValue, countType) || null;
|
|
102
|
+
return DateUtils.getDateByGranularity(cellValue, countType, firstDayOfWeek) || null;
|
|
102
103
|
}
|
|
103
104
|
if (result_type === FORMULA_RESULT_TYPE.BOOL) {
|
|
104
105
|
return !!cellValue;
|
|
@@ -106,7 +107,7 @@ var _getFormattedCellValue = function _getFormattedCellValue(cellValue, groupby)
|
|
|
106
107
|
if (result_type === FORMULA_RESULT_TYPE.ARRAY) {
|
|
107
108
|
var newCellValue = cellValue;
|
|
108
109
|
if (isDateColumn(column) && Array.isArray(cellValue) && cellValue.length > 0) {
|
|
109
|
-
return DateUtils.getDateByGranularity(cellValue[0], countType) || null;
|
|
110
|
+
return DateUtils.getDateByGranularity(cellValue[0], countType, firstDayOfWeek) || null;
|
|
110
111
|
}
|
|
111
112
|
|
|
112
113
|
// convert to string
|
|
@@ -254,6 +255,12 @@ var _getSortedGroups = function getSortedGroups(groups, groupbys, value, level)
|
|
|
254
255
|
};
|
|
255
256
|
var groupRowsWithMultipleGroupbys = function groupRowsWithMultipleGroupbys(groupbys, rows, formulaRows, value) {
|
|
256
257
|
var validGroupbys = groupbys.length > MAX_GROUP_LEVEL ? groupbys.slice(0, MAX_GROUP_LEVEL) : _toConsumableArray(groupbys);
|
|
258
|
+
var settings = value.settings;
|
|
259
|
+
var _ref3 = settings || {},
|
|
260
|
+
date_settings = _ref3.date_settings;
|
|
261
|
+
var _ref4 = date_settings || {},
|
|
262
|
+
_ref4$first_day_of_we = _ref4.first_day_of_week,
|
|
263
|
+
firstDayOfWeek = _ref4$first_day_of_we === void 0 ? 'Monday' : _ref4$first_day_of_we;
|
|
257
264
|
var groups = [];
|
|
258
265
|
var cellValue2GroupIndexMap = {};
|
|
259
266
|
rows.forEach(function (row) {
|
|
@@ -266,7 +273,7 @@ var groupRowsWithMultipleGroupbys = function groupRowsWithMultipleGroupbys(group
|
|
|
266
273
|
column_key = currentGroupby.column_key;
|
|
267
274
|
var columnType = column.type;
|
|
268
275
|
var cellValue = _getCellValue(row, formulaRows, currentGroupby);
|
|
269
|
-
var formattedValue = _getFormattedCellValue(cellValue, currentGroupby);
|
|
276
|
+
var formattedValue = _getFormattedCellValue(cellValue, currentGroupby, firstDayOfWeek);
|
|
270
277
|
var sCellValue = _getStrCellValue(formattedValue, columnType);
|
|
271
278
|
var group = {
|
|
272
279
|
cell_value: formattedValue,
|
|
@@ -331,11 +338,17 @@ var groupTableRows = function groupTableRows(groupbys, rows, formulaRows, value)
|
|
|
331
338
|
var column_key = groupby.column_key,
|
|
332
339
|
column = groupby.column;
|
|
333
340
|
var columnType = column.type;
|
|
341
|
+
var settings = value.settings;
|
|
342
|
+
var _ref5 = settings || {},
|
|
343
|
+
date_settings = _ref5.date_settings;
|
|
344
|
+
var _ref6 = date_settings || {},
|
|
345
|
+
_ref6$first_day_of_we = _ref6.first_day_of_week,
|
|
346
|
+
firstDayOfWeek = _ref6$first_day_of_we === void 0 ? 'Monday' : _ref6$first_day_of_we;
|
|
334
347
|
var groups = [];
|
|
335
348
|
var cellValue2GroupIndexMap = {};
|
|
336
349
|
rows.forEach(function (r) {
|
|
337
350
|
var cellValue = _getCellValue(r, formulaRows, groupby);
|
|
338
|
-
var formattedValue = _getFormattedCellValue(cellValue, groupby);
|
|
351
|
+
var formattedValue = _getFormattedCellValue(cellValue, groupby, firstDayOfWeek);
|
|
339
352
|
var sCellValue = _getStrCellValue(formattedValue, columnType);
|
|
340
353
|
var groupedRowIndex = _findGroupIndex(sCellValue, cellValue2GroupIndexMap, groups.length);
|
|
341
354
|
if (groupedRowIndex > -1) {
|
|
@@ -389,9 +402,9 @@ var groupViewRows = function groupViewRows(groupbys, table, rowsIds, formulaRows
|
|
|
389
402
|
row_ids, subgroups, summaries, ...}, ...], array
|
|
390
403
|
*/
|
|
391
404
|
var getGroupedRowsWithoutFormulaCalculation = function getGroupedRowsWithoutFormulaCalculation(groupbys, rows, table, value) {
|
|
392
|
-
var
|
|
393
|
-
|
|
394
|
-
formulaRows =
|
|
405
|
+
var _ref7 = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {},
|
|
406
|
+
_ref7$formulaRows = _ref7.formulaRows,
|
|
407
|
+
formulaRows = _ref7$formulaRows === void 0 ? null : _ref7$formulaRows;
|
|
395
408
|
var columns = table.columns;
|
|
396
409
|
var validGroupbys = deleteInvalidGroupby(groupbys, columns, table, value);
|
|
397
410
|
return isTableRows(rows) ? groupTableRows(validGroupbys, rows, formulaRows, value) : groupViewRows(validGroupbys, table, rows, formulaRows, value);
|
package/es/view/summaries.js
CHANGED
|
@@ -15,6 +15,7 @@ import '../constants/filter/filter-is-within.js';
|
|
|
15
15
|
import '../constants/sort.js';
|
|
16
16
|
import '../constants/group.js';
|
|
17
17
|
import { isNumericColumn } from '../column/number.js';
|
|
18
|
+
import '@babel/runtime/helpers/slicedToArray';
|
|
18
19
|
import 'dayjs';
|
|
19
20
|
import { getGroupsRowIds as _getGroupsRowIds } from '../group/core.js';
|
|
20
21
|
|
|
@@ -18,6 +18,7 @@ require('@babel/runtime/helpers/typeof');
|
|
|
18
18
|
require('../../date.js');
|
|
19
19
|
require('@babel/runtime/helpers/defineProperty');
|
|
20
20
|
require('@babel/runtime/helpers/toConsumableArray');
|
|
21
|
+
require('@babel/runtime/helpers/slicedToArray');
|
|
21
22
|
|
|
22
23
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
23
24
|
|
|
@@ -139,7 +139,6 @@ var getFormulaDisplayString = function getFormulaDisplayString(cellValue, column
|
|
|
139
139
|
* @param {object} formulaRows formula results of rows. Default as "{}"
|
|
140
140
|
* @param {array} collaborators e.g. [{ email, name, ... }, ...]. Default as "[]"
|
|
141
141
|
* @param {array} departments e.g. [{ name, id }, ...]. Default as "[]"
|
|
142
|
-
* @param {bool} isBaiduMap Determine the way to connect latitude and longitude. Default as true
|
|
143
142
|
* @param {string} geolocationHyphen Used as a connector between province, city, district and detail. Default as empty string
|
|
144
143
|
* @returns formatted cell value, string|array
|
|
145
144
|
*/
|
|
@@ -152,8 +151,6 @@ var getCellValueDisplayString = function getCellValueDisplayString(row, type, ke
|
|
|
152
151
|
collaborators = _ref2$collaborators === void 0 ? [] : _ref2$collaborators,
|
|
153
152
|
_ref2$departments = _ref2.departments,
|
|
154
153
|
departments = _ref2$departments === void 0 ? [] : _ref2$departments,
|
|
155
|
-
_ref2$isBaiduMap = _ref2.isBaiduMap,
|
|
156
|
-
isBaiduMap = _ref2$isBaiduMap === void 0 ? true : _ref2$isBaiduMap,
|
|
157
154
|
_ref2$geolocationHyph = _ref2.geolocationHyphen,
|
|
158
155
|
geolocationHyphen = _ref2$geolocationHyph === void 0 ? '' : _ref2$geolocationHyph;
|
|
159
156
|
if (!row) return '';
|
|
@@ -174,7 +171,6 @@ var getCellValueDisplayString = function getCellValueDisplayString(row, type, ke
|
|
|
174
171
|
case cellType.CellType.GEOLOCATION:
|
|
175
172
|
{
|
|
176
173
|
return geolocation.getGeolocationDisplayString(cellValue, data, {
|
|
177
|
-
isBaiduMap: isBaiduMap,
|
|
178
174
|
hyphen: geolocationHyphen
|
|
179
175
|
});
|
|
180
176
|
}
|
|
@@ -4,20 +4,55 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var group = require('../constants/group.js');
|
|
6
6
|
var column = require('../constants/column.js');
|
|
7
|
-
var
|
|
7
|
+
var number = require('../number.js');
|
|
8
|
+
var geolocation = require('../constants/geolocation.js');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Convert decimal to DMS
|
|
12
|
+
* @param {number} lat
|
|
13
|
+
* @param {bool} isLat Latitude: N/S, Longitude: E/W
|
|
14
|
+
* @returns { dms, direction }, object
|
|
15
|
+
*/
|
|
16
|
+
var convertToDMS = function convertToDMS(decimal) {
|
|
17
|
+
var isLat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
18
|
+
if (!number.isNumber(decimal) && typeof decimal !== 'string') return {};
|
|
19
|
+
var numDecimal = typeof decimal === 'string' ? Number.parseFloat(decimal) : decimal;
|
|
20
|
+
if (!number.isNumber(numDecimal)) return {};
|
|
21
|
+
var degrees = Math.floor(Math.abs(numDecimal));
|
|
22
|
+
var minutesDecimal = Number.parseFloat(((Math.abs(numDecimal) - degrees) * 60).toFixed(8));
|
|
23
|
+
var minutes = Math.floor(minutesDecimal);
|
|
24
|
+
var seconds = Number.parseFloat(((minutesDecimal - minutes) * 60).toFixed(8));
|
|
25
|
+
var direction = '';
|
|
26
|
+
if (isLat) {
|
|
27
|
+
direction = numDecimal >= 0 ? geolocation.LAT_DIRECTION_TYPE.N : geolocation.LAT_DIRECTION_TYPE.S;
|
|
28
|
+
} else {
|
|
29
|
+
direction = numDecimal >= 0 ? geolocation.LNG_DIRECTION_TYPE.E : geolocation.LNG_DIRECTION_TYPE.W;
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
dms: "".concat(degrees).concat(geolocation.DMS_SPLITTER_TYPE.DEG).concat(minutes).concat(geolocation.DMS_SPLITTER_TYPE.MIN).concat(seconds).concat(geolocation.DMS_SPLITTER_TYPE.SEC),
|
|
33
|
+
direction: direction
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
var getLatLngDisplayString = function getLatLngDisplayString(lat, lng) {
|
|
37
|
+
var _convertToDMS = convertToDMS(lat, true),
|
|
38
|
+
lat_dms = _convertToDMS.dms,
|
|
39
|
+
lat_direction = _convertToDMS.direction;
|
|
40
|
+
var _convertToDMS2 = convertToDMS(lng),
|
|
41
|
+
lng_dms = _convertToDMS2.dms,
|
|
42
|
+
lng_direction = _convertToDMS2.direction;
|
|
43
|
+
if (!lat_dms || !lng_dms) return '';
|
|
44
|
+
return "".concat(lat_direction).concat(lat_dms, ", ").concat(lng_direction).concat(lng_dms);
|
|
45
|
+
};
|
|
8
46
|
|
|
9
47
|
/**
|
|
10
48
|
* Get formatted geolocation
|
|
11
49
|
* @param {object} loc
|
|
12
50
|
* @param {object} formats , e.g. { geo_format, ... }
|
|
13
|
-
* @param {bool} isBaiduMap Determine the way to connect latitude and longitude. Default as true
|
|
14
51
|
* @param {string} hyphen Used as a connector between province, city, district and detail. Default as empty string
|
|
15
52
|
* @returns formatted geolocation, string
|
|
16
53
|
*/
|
|
17
54
|
var getGeolocationDisplayString = function getGeolocationDisplayString(loc, formats) {
|
|
18
55
|
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
19
|
-
_ref$isBaiduMap = _ref.isBaiduMap,
|
|
20
|
-
isBaiduMap = _ref$isBaiduMap === void 0 ? true : _ref$isBaiduMap,
|
|
21
56
|
_ref$hyphen = _ref.hyphen,
|
|
22
57
|
hyphen = _ref$hyphen === void 0 ? '' : _ref$hyphen;
|
|
23
58
|
if (!loc) return '';
|
|
@@ -28,8 +63,7 @@ var getGeolocationDisplayString = function getGeolocationDisplayString(loc, form
|
|
|
28
63
|
{
|
|
29
64
|
var lng = loc.lng,
|
|
30
65
|
lat = loc.lat;
|
|
31
|
-
|
|
32
|
-
return isBaiduMap ? "".concat(lng, ", ").concat(lat) : "".concat(lat, ", ").concat(lng);
|
|
66
|
+
return getLatLngDisplayString(lat, lng);
|
|
33
67
|
}
|
|
34
68
|
case column.GEOLOCATION_FORMAT.COUNTRY_REGION:
|
|
35
69
|
{
|
|
@@ -105,5 +139,7 @@ var getGeolocationByGranularity = function getGeolocationByGranularity(geolocati
|
|
|
105
139
|
}
|
|
106
140
|
};
|
|
107
141
|
|
|
142
|
+
exports.convertToDMS = convertToDMS;
|
|
108
143
|
exports.getGeolocationByGranularity = getGeolocationByGranularity;
|
|
109
144
|
exports.getGeolocationDisplayString = getGeolocationDisplayString;
|
|
145
|
+
exports.getLatLngDisplayString = getLatLngDisplayString;
|