dtable-utils 0.0.3-beta.1 → 0.0.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.
Files changed (152) hide show
  1. package/README.md +2 -30
  2. package/dist/index.js +1 -1
  3. package/es/cell-value-get/cell-value.js +19 -227
  4. package/es/cell-value-get/collaborator.js +3 -9
  5. package/es/cell-value-get/digital-sign.js +1 -1
  6. package/es/cell-value-get/duration.js +1 -1
  7. package/es/cell-value-get/geolocation.js +5 -29
  8. package/es/cell-value-get/long-text.js +1 -1
  9. package/es/cell-value-get/number.js +18 -42
  10. package/es/cell-value-get/option.js +7 -17
  11. package/es/cell-value-set/number.js +1 -53
  12. package/es/column/{core.js → common.js} +14 -2
  13. package/es/column/date.js +1 -1
  14. package/es/column/number.js +1 -1
  15. package/es/common.js +10 -9
  16. package/es/constants/column.js +2 -127
  17. package/es/constants/filter/index.js +1 -5
  18. package/es/date.js +1 -1
  19. package/es/index.js +10 -62
  20. package/es/validate/filter.js +1 -1
  21. package/lib/cell-value-get/cell-value.js +18 -231
  22. package/lib/cell-value-get/collaborator.js +2 -9
  23. package/lib/cell-value-get/digital-sign.js +1 -1
  24. package/lib/cell-value-get/duration.js +1 -0
  25. package/lib/cell-value-get/geolocation.js +5 -30
  26. package/lib/cell-value-get/long-text.js +1 -1
  27. package/lib/cell-value-get/number.js +17 -42
  28. package/lib/cell-value-get/option.js +6 -18
  29. package/lib/cell-value-set/number.js +0 -53
  30. package/lib/column/{core.js → common.js} +14 -1
  31. package/lib/column/date.js +2 -2
  32. package/lib/column/number.js +3 -3
  33. package/lib/common.js +11 -13
  34. package/lib/constants/column.js +1 -134
  35. package/lib/constants/filter/index.js +0 -5
  36. package/lib/index.js +8 -176
  37. package/lib/validate/filter.js +3 -3
  38. package/package.json +3 -5
  39. package/es/cell-value-get/rate.js +0 -6
  40. package/es/cell-value-set/date.js +0 -20
  41. package/es/color/gradient-color.js +0 -100
  42. package/es/column/color.js +0 -415
  43. package/es/column/option.js +0 -115
  44. package/es/constants/color.js +0 -16
  45. package/es/constants/column-permission.js +0 -7
  46. package/es/constants/grid-header.js +0 -6
  47. package/es/constants/group.js +0 -23
  48. package/es/constants/limit.js +0 -3
  49. package/es/constants/reg.js +0 -4
  50. package/es/constants/row-color.js +0 -11
  51. package/es/constants/sort.js +0 -11
  52. package/es/filter/core.js +0 -287
  53. package/es/filter/filter-column/array.js +0 -82
  54. package/es/filter/filter-column/checkbox.js +0 -8
  55. package/es/filter/filter-column/collaborator.js +0 -67
  56. package/es/filter/filter-column/creator.js +0 -50
  57. package/es/filter/filter-column/date.js +0 -59
  58. package/es/filter/filter-column/digital-sign.js +0 -26
  59. package/es/filter/filter-column/file.js +0 -24
  60. package/es/filter/filter-column/formula.js +0 -49
  61. package/es/filter/filter-column/geolocation.js +0 -53
  62. package/es/filter/filter-column/link.js +0 -12
  63. package/es/filter/filter-column/long-text.js +0 -25
  64. package/es/filter/filter-column/multiple-select.js +0 -60
  65. package/es/filter/filter-column/number.js +0 -93
  66. package/es/filter/filter-column/single-select.js +0 -41
  67. package/es/filter/filter-column/text.js +0 -55
  68. package/es/filter/filter-row.js +0 -198
  69. package/es/group/core.js +0 -107
  70. package/es/group/group-row.js +0 -366
  71. package/es/link/core.js +0 -78
  72. package/es/number.js +0 -13
  73. package/es/row/color.js +0 -278
  74. package/es/row/core.js +0 -161
  75. package/es/sort/core.js +0 -32
  76. package/es/sort/sort-column/array.js +0 -63
  77. package/es/sort/sort-column/checkbox.js +0 -15
  78. package/es/sort/sort-column/collaborator.js +0 -9
  79. package/es/sort/sort-column/date.js +0 -25
  80. package/es/sort/sort-column/formula.js +0 -40
  81. package/es/sort/sort-column/link.js +0 -23
  82. package/es/sort/sort-column/multiple-select.js +0 -45
  83. package/es/sort/sort-column/number.js +0 -18
  84. package/es/sort/sort-column/single-select.js +0 -22
  85. package/es/sort/sort-column/text.js +0 -47
  86. package/es/sort/sort-row.js +0 -126
  87. package/es/table/column.js +0 -27
  88. package/es/table/core.js +0 -14
  89. package/es/table/index.js +0 -14
  90. package/es/table/row.js +0 -25
  91. package/es/validate/geolocation.js +0 -5
  92. package/es/view/core.js +0 -135
  93. package/es/view/formula.js +0 -143
  94. package/es/view/group.js +0 -32
  95. package/es/view/summaries.js +0 -179
  96. package/lib/cell-value-get/rate.js +0 -10
  97. package/lib/cell-value-set/date.js +0 -24
  98. package/lib/color/gradient-color.js +0 -110
  99. package/lib/column/color.js +0 -424
  100. package/lib/column/option.js +0 -123
  101. package/lib/constants/color.js +0 -20
  102. package/lib/constants/column-permission.js +0 -11
  103. package/lib/constants/grid-header.js +0 -10
  104. package/lib/constants/group.js +0 -36
  105. package/lib/constants/limit.js +0 -7
  106. package/lib/constants/reg.js +0 -9
  107. package/lib/constants/row-color.js +0 -17
  108. package/lib/constants/sort.js +0 -18
  109. package/lib/filter/core.js +0 -301
  110. package/lib/filter/filter-column/array.js +0 -86
  111. package/lib/filter/filter-column/checkbox.js +0 -12
  112. package/lib/filter/filter-column/collaborator.js +0 -75
  113. package/lib/filter/filter-column/creator.js +0 -54
  114. package/lib/filter/filter-column/date.js +0 -63
  115. package/lib/filter/filter-column/digital-sign.js +0 -30
  116. package/lib/filter/filter-column/file.js +0 -28
  117. package/lib/filter/filter-column/formula.js +0 -53
  118. package/lib/filter/filter-column/geolocation.js +0 -57
  119. package/lib/filter/filter-column/link.js +0 -16
  120. package/lib/filter/filter-column/long-text.js +0 -29
  121. package/lib/filter/filter-column/multiple-select.js +0 -68
  122. package/lib/filter/filter-column/number.js +0 -97
  123. package/lib/filter/filter-column/single-select.js +0 -45
  124. package/lib/filter/filter-column/text.js +0 -59
  125. package/lib/filter/filter-row.js +0 -204
  126. package/lib/group/core.js +0 -117
  127. package/lib/group/group-row.js +0 -377
  128. package/lib/link/core.js +0 -90
  129. package/lib/number.js +0 -18
  130. package/lib/row/color.js +0 -286
  131. package/lib/row/core.js +0 -170
  132. package/lib/sort/core.js +0 -37
  133. package/lib/sort/sort-column/array.js +0 -67
  134. package/lib/sort/sort-column/checkbox.js +0 -19
  135. package/lib/sort/sort-column/collaborator.js +0 -13
  136. package/lib/sort/sort-column/date.js +0 -29
  137. package/lib/sort/sort-column/formula.js +0 -44
  138. package/lib/sort/sort-column/link.js +0 -27
  139. package/lib/sort/sort-column/multiple-select.js +0 -50
  140. package/lib/sort/sort-column/number.js +0 -22
  141. package/lib/sort/sort-column/single-select.js +0 -26
  142. package/lib/sort/sort-column/text.js +0 -52
  143. package/lib/sort/sort-row.js +0 -136
  144. package/lib/table/column.js +0 -32
  145. package/lib/table/core.js +0 -18
  146. package/lib/table/index.js +0 -18
  147. package/lib/table/row.js +0 -30
  148. package/lib/validate/geolocation.js +0 -9
  149. package/lib/view/core.js +0 -144
  150. package/lib/view/formula.js +0 -150
  151. package/lib/view/group.js +0 -36
  152. package/lib/view/summaries.js +0 -185
@@ -1,179 +0,0 @@
1
- import { getRowsByIds } from '../table/row.js';
2
- import { isTableRows } from '../row/core.js';
3
- import '@babel/runtime/helpers/defineProperty';
4
- import '../constants/group.js';
5
- import '../validate/filter.js';
6
- import '../filter/core.js';
7
- import '@babel/runtime/helpers/toConsumableArray';
8
- import '../constants/filter/filter-column-options.js';
9
- import '../constants/filter/filter-modifier.js';
10
- import '../constants/filter/filter-predicate.js';
11
- import '../constants/filter/filter-is-within.js';
12
- import '../date.js';
13
- import { isNumber } from '../number.js';
14
- import '../cell-value-get/cell-value.js';
15
- import { isNumericColumn } from '../column/number.js';
16
- import '../constants/column.js';
17
- import { FORMULA_COLUMN_TYPES_MAP } from '../constants/formula.js';
18
- import '../constants/row-color.js';
19
-
20
- /**
21
- * calculate summaries of numeric columns from table
22
- * @param {object} table
23
- * @param {array} rows table's rows or rows ids
24
- * @param {object} formulaRows support numeric formula columns
25
- * @returns object, { [column.key]: { sum, average, median, max, min, ... }, ... }
26
- */
27
- var getSummaries = function getSummaries(table, rows, formulaRows) {
28
- var numericColumns = table.columns.filter(function (column) {
29
- return isNumericColumn(column);
30
- });
31
- if (numericColumns.length === 0) {
32
- return {};
33
- }
34
- var summaryRows = isTableRows(rows) ? rows : getRowsByIds(table, rows);
35
- var summaries = {};
36
- numericColumns.forEach(function (column) {
37
- var type = column.type,
38
- key = column.key;
39
- var validNumbersCount = 0;
40
- var medianArr = [];
41
- var sum = 0;
42
- var min;
43
- var max;
44
- var median;
45
- summaryRows.forEach(function (row) {
46
- var cellValue = row[key];
47
- if (FORMULA_COLUMN_TYPES_MAP[type]) {
48
- var formulaRow = formulaRows && formulaRows[row._id];
49
- cellValue = formulaRow && formulaRow[key];
50
- if (Array.isArray(cellValue) && cellValue.length === 1) {
51
- cellValue = cellValue[0];
52
- }
53
- }
54
- if (isNumber(cellValue)) {
55
- medianArr.push(cellValue);
56
- validNumbersCount += 1;
57
- sum += cellValue;
58
- if (min === undefined) {
59
- min = cellValue;
60
- } else {
61
- min = cellValue < min ? cellValue : min;
62
- }
63
- if (max === undefined) {
64
- max = cellValue;
65
- } else {
66
- max = cellValue > max ? cellValue : max;
67
- }
68
- }
69
- });
70
- if (validNumbersCount > 0) {
71
- medianArr.sort();
72
- if (medianArr.length % 2 === 0) {
73
- median = (medianArr[medianArr.length / 2 - 1] + medianArr[medianArr.length / 2]) / 2;
74
- } else {
75
- median = medianArr[parseInt(medianArr.length / 2)];
76
- }
77
- }
78
- var average = validNumbersCount === 0 ? 0 : sum / validNumbersCount;
79
- summaries[key] = {
80
- sum: sum,
81
- average: average,
82
- median: median,
83
- max: max,
84
- min: min
85
- };
86
- });
87
- return summaries;
88
- };
89
-
90
- /**
91
- * calculate sub-group's summaries of numeric columns
92
- * @param {array} subgroups { summaries, ... }
93
- * @param {array} numericColumns
94
- * @returns object, { [column.key]: { sum, average, median, max, min, ... } }
95
- */
96
- var getSummariesWithSubgroups = function getSummariesWithSubgroups(subgroups, numericColumns) {
97
- var subgroupsLen = subgroups.length;
98
- var summaries = {};
99
- numericColumns.forEach(function (column) {
100
- var medianArr = [];
101
- var sum = 0;
102
- var average = 0;
103
- var median;
104
- var max;
105
- var min;
106
- subgroups.forEach(function (subgroup) {
107
- var summaries = subgroup.summaries;
108
- var summary = summaries[column.key];
109
- var subgroupSum = summary.sum,
110
- subgroupAverage = summary.average,
111
- subgroupMedian = summary.median,
112
- subgroupMax = summary.max,
113
- subgroupMin = summary.min;
114
- sum += subgroupSum || 0;
115
- average += subgroupAverage || 0;
116
- if (isNumber(subgroupMedian)) {
117
- medianArr.push(subgroupMedian);
118
- }
119
- if (isNumber(subgroupMax)) {
120
- if (max === undefined) {
121
- max = subgroupMax;
122
- } else {
123
- max = subgroupMax > max ? subgroupMax : max;
124
- }
125
- }
126
- if (isNumber(subgroupMin)) {
127
- if (min === undefined) {
128
- min = subgroupMin;
129
- } else {
130
- min = subgroupMin < min ? subgroupMin : min;
131
- }
132
- }
133
- });
134
- if (medianArr.length > 0) {
135
- medianArr.sort();
136
- if (medianArr.length % 2 === 0) {
137
- median = (medianArr[medianArr.length / 2 - 1] + medianArr[medianArr.length / 2]) / 2;
138
- } else {
139
- median = medianArr[parseInt(medianArr.length / 2)];
140
- }
141
- }
142
- average = average / subgroupsLen;
143
- summaries[column.key] = {
144
- sum: sum,
145
- average: average,
146
- median: median,
147
- max: max,
148
- min: min
149
- };
150
- });
151
- return summaries;
152
- };
153
-
154
- /**
155
- * calculate group's summaries of numeric columns from table
156
- * @param {array} groups { subgroups, row_ids, ... }
157
- * @param {object} table
158
- * @param {object} formulaRows support numeric formula columns
159
- */
160
- var updateGroupSummaries = function updateGroupSummaries(groups, table, formulaRows) {
161
- var numericColumns = table.columns.filter(function (column) {
162
- return isNumericColumn(column);
163
- });
164
- if (!Array.isArray(groups) || numericColumns.length === 0) {
165
- return;
166
- }
167
- groups.forEach(function (group) {
168
- var subgroups = group.subgroups,
169
- row_ids = group.row_ids;
170
- if (Array.isArray(subgroups) && subgroups.length > 0) {
171
- updateGroupSummaries(subgroups, table, formulaRows);
172
- group.summaries = getSummariesWithSubgroups(subgroups, numericColumns);
173
- } else if (row_ids) {
174
- group.summaries = getSummaries(table, row_ids, formulaRows);
175
- }
176
- });
177
- };
178
-
179
- export { getSummaries, getSummariesWithSubgroups, updateGroupSummaries };
@@ -1,10 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var getRateDisplayString = function getRateDisplayString(value) {
6
- if (!value) return '';
7
- return String(value);
8
- };
9
-
10
- exports.getRateDisplayString = getRateDisplayString;
@@ -1,24 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var date = require('../date.js');
6
- var number = require('./number.js');
7
-
8
- var formatTextToDate = function formatTextToDate(text) {
9
- var dateFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'YYYY-MM-DD';
10
- if (typeof text !== 'string' || !text.trim()) return null;
11
- var isAllNumber = /^[0-9]+$/.test(text);
12
- var dateObj = {};
13
- if (isAllNumber) {
14
- dateObj = new Date(number.getFloatNumber(text));
15
- } else {
16
- dateObj = date.DateUtils.parseDateWithFormat(text, dateFormat);
17
- }
18
- if (dateFormat.indexOf('HH:mm') < 0) {
19
- return date.DateUtils.format(dateObj, 'YYYY-MM-DD') || null;
20
- }
21
- return date.DateUtils.format(dateObj, 'YYYY-MM-DD HH:MM') || null;
22
- };
23
-
24
- exports.formatTextToDate = formatTextToDate;
@@ -1,110 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
6
- var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
7
- var _createClass = require('@babel/runtime/helpers/createClass');
8
- var color = require('../constants/color.js');
9
-
10
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
-
12
- var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
13
- var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
14
- var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
15
-
16
- var GradientColorUtils = /*#__PURE__*/function () {
17
- function GradientColorUtils(_ref) {
18
- var colorType = _ref.colorType,
19
- max = _ref.max,
20
- min = _ref.min;
21
- _classCallCheck__default["default"](this, GradientColorUtils);
22
- var newColorType = colorType || 'color_gradation_1';
23
- var colors = color.COLOR_GRADATION_OPTIONS[newColorType];
24
- this.startColor = this.hexToRgb(colors[0]);
25
- this.endColor = this.hexToRgb(colors[4]);
26
- this.min = min;
27
- this.max = max;
28
- this.computeMap = {};
29
- }
30
- _createClass__default["default"](GradientColorUtils, [{
31
- key: "hexToRgb",
32
- value: function hexToRgb(hexCode) {
33
- var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
34
- var nextHexCode = hexCode.toLowerCase();
35
- if (nextHexCode && reg.test(nextHexCode)) {
36
- if (nextHexCode.length === 4) {
37
- var newHexCode = '#';
38
- for (var i = 1; i < 4; i += 1) {
39
- newHexCode += nextHexCode.slice(i, i + 1).concat(nextHexCode.slice(i, i + 1));
40
- }
41
- nextHexCode = newHexCode;
42
- }
43
- var hexCodeChange = [];
44
- for (var _i = 1; _i < 7; _i += 2) {
45
- hexCodeChange.push(parseInt("0x".concat(nextHexCode.slice(_i, _i + 2))));
46
- }
47
- return "RGB(".concat(hexCodeChange.join(','), ")");
48
- }
49
- return nextHexCode;
50
- }
51
- }, {
52
- key: "getColorGradation",
53
- value: function getColorGradation(color1, color2, value1, value2, value) {
54
- var rgb1 = color1.split(',');
55
- var r1 = parseInt(rgb1[0].split('(')[1]);
56
- var g1 = parseInt(rgb1[1]);
57
- var b1 = parseInt(rgb1[2].split(')')[0]);
58
- var rgb2 = color2.split(',');
59
- var r2 = parseInt(rgb2[0].split('(')[1]);
60
- var g2 = parseInt(rgb2[1]);
61
- var b2 = parseInt(rgb2[2].split(')')[0]);
62
- var r = Math.round(r1 - (r1 - r2) / (value1 - value2) * (value1 - value));
63
- var g = Math.round(g1 - (g1 - g2) / (value1 - value2) * (value1 - value));
64
- var b = Math.round(b1 - (b1 - b2) / (value1 - value2) * (value1 - value));
65
- return "rgb(".concat(r, ", ").concat(g, ", ").concat(b, ")");
66
- }
67
- }, {
68
- key: "getCellColor",
69
- value: function getCellColor(value) {
70
- if (this.computeMap[value]) {
71
- return this.computeMap[value];
72
- }
73
-
74
- // eslint-disable-next-line
75
- if (value == this.min) {
76
- if (this.computeMap[value]) {
77
- this.computeMap[value] = this.startColor;
78
- } else {
79
- this.computeMap = _defineProperty__default["default"]({}, value, this.startColor);
80
- }
81
- return this.computeMap[value];
82
- }
83
-
84
- // eslint-disable-next-line
85
- if (value == this.max) {
86
- if (this.computeMap[value]) {
87
- this.computeMap[value] = this.endColor;
88
- } else {
89
- this.computeMap = _defineProperty__default["default"]({}, value, this.endColor);
90
- }
91
- return this.computeMap[value];
92
- }
93
- if (value > this.min && value < this.max) {
94
- var color1 = this.startColor,
95
- color2 = this.endColor,
96
- value1 = this.min,
97
- value2 = this.max;
98
- var color = this.getColorGradation(color1, color2, value1, value2, value);
99
- this.computeMap[value] = color;
100
- return this.computeMap[value];
101
- }
102
-
103
- // value < min || value > max
104
- return null;
105
- }
106
- }]);
107
- return GradientColorUtils;
108
- }();
109
-
110
- exports["default"] = GradientColorUtils;